diff --git a/app/src/lib/graph-interface/graph/Graph.svelte b/app/src/lib/graph-interface/graph/Graph.svelte index ddf493a..ea6c504 100644 --- a/app/src/lib/graph-interface/graph/Graph.svelte +++ b/app/src/lib/graph-interface/graph/Graph.svelte @@ -52,7 +52,6 @@ let mouseDown: null | [number, number] = null; let mouseDownId = -1; let boxSelection = false; - let loaded = false; const cameraDown = [0, 0]; let cameraPosition: [number, number, number] = [0, 0, 4]; let addMenuPosition: [number, number] | null = null; @@ -783,7 +782,7 @@ event.preventDefault(); isDragging = false; if (!event.dataTransfer) return; - const nodeId: NodeId = event.dataTransfer.getData("data/node-id"); + const nodeId = event.dataTransfer.getData("data/node-id") as NodeId; if (nodeId) { let mx = event.clientX - rect.x; @@ -805,7 +804,7 @@ } const pos = projectScreenToWorld(mx, my); - graph.load([nodeId]).then(() => { + graph.registry.load([nodeId]).then(() => { graph.createNode({ type: nodeId, props, diff --git a/app/src/lib/helpers/index.ts b/app/src/lib/helpers/index.ts index fde4e8a..f48d7a1 100644 --- a/app/src/lib/helpers/index.ts +++ b/app/src/lib/helpers/index.ts @@ -114,3 +114,15 @@ export function withSubComponents>( }); return component as A & B; } + +export function humanizeNumber(number: number): string { + const suffixes = ["", "K", "M", "B", "T"]; + if (number < 1000) { + return number.toString(); + } + const numLength = Math.floor(Math.log10(number)) + 1; + const baseIndex = Math.floor((numLength - 1) / 3); + const base = Math.pow(10, baseIndex * 3); + const rounded = Math.round(number / base * 10) / 10; + return rounded + suffixes[baseIndex]; +} diff --git a/app/src/lib/performance/Monitor.svelte b/app/src/lib/performance/Monitor.svelte new file mode 100644 index 0000000..0ba767b --- /dev/null +++ b/app/src/lib/performance/Monitor.svelte @@ -0,0 +1,68 @@ + + +
+

Runtime Execution

+ {min}ms + {max}ms + + + +
+ + diff --git a/app/src/lib/performance/PerformanceViewer.svelte b/app/src/lib/performance/PerformanceViewer.svelte index 23f72ed..a6cda26 100644 --- a/app/src/lib/performance/PerformanceViewer.svelte +++ b/app/src/lib/performance/PerformanceViewer.svelte @@ -1,17 +1,122 @@ -{#if data.runs.length !== 0} - {#each getPerformanceData() as [key, value]} -

{key}: {Math.floor(value * 100) / 100}ms

- {/each} -{:else} -

No runs available

-{/if} +{#key data} + {#if browser} + + {/if} + +
+ {#if data.runs.length !== 0} +

General

+ + {#each getPerformanceData() as [key, value]} + + + + + {/each} + +

Nodes

+ {#each getNodePerformanceData() as [key, value]} + + + + + {/each} + + {#if viewer.runs.length} +

Viewer

+ + + + + + + + + {#each getViewerPerformanceData() as [key, value]} + + + + + {/each} + {/if} +
+ {Math.floor(value * 100) / 100}ms + + {key} +
+ {Math.floor(value * 100) / 100}ms + + {key.split("/").slice(-1).join("/")} +
{humanizeNumber(viewer.runs.at(-1)?.["total-vertices"])}Vertices
{humanizeNumber(viewer.runs.at(-1)?.["total-faces"])}Faces
+ {Math.floor(value * 100) / 100}ms + + {key.split("/").slice(-1).join("/")} +
+ {:else} +

No runs available

+ {/if} +
+{/key} + + diff --git a/app/src/lib/performance/index.ts b/app/src/lib/performance/index.ts index 761dcdd..0d8ab3d 100644 --- a/app/src/lib/performance/index.ts +++ b/app/src/lib/performance/index.ts @@ -1,68 +1,2 @@ -import { readable, type Readable } from "svelte/store"; - -export type PerformanceData = { - total: Record; - runs: Record[]; -} -export interface PerformanceStore extends Readable { - startRun(): void; - stopRun(): void; - addPoint(name: string, value?: number): void; - get: () => PerformanceData; -} - -export function createPerformanceStore(): PerformanceStore { - - let data: PerformanceData = { total: {}, runs: [] }; - - let currentRun: Record | undefined; - - let set: (v: PerformanceData) => void; - - const { subscribe } = readable({ total: {}, runs: [] }, (_set) => { - set = _set; - }); - - function startRun() { - currentRun = {}; - } - - function stopRun() { - if (currentRun) { - // Calculate total - Object.keys(currentRun).forEach((name) => { - if (!currentRun?.[name]?.length) return; - let runTotal = currentRun[name].reduce((a, b) => a + b, 0) / currentRun[name].length; - if (!data.total[name]) { - data.total[name] = runTotal; - } else { - data.total[name] = (data.total[name] + runTotal) / 2; - } - }); - - data.runs.push(currentRun); - currentRun = undefined; - if (set) set(data); - } - } - - function addPoint(name: string, value: number) { - if (!currentRun) return; - currentRun[name] = currentRun[name] || []; - currentRun[name].push(value); - } - - function get() { - return data; - } - - return { - subscribe, - startRun, - stopRun, - addPoint, - get - } -} - +export * from "./store"; export { default as PerformanceViewer } from "./PerformanceViewer.svelte"; diff --git a/app/src/lib/performance/store.ts b/app/src/lib/performance/store.ts new file mode 100644 index 0000000..75a66fd --- /dev/null +++ b/app/src/lib/performance/store.ts @@ -0,0 +1,67 @@ +import { readable, type Readable } from "svelte/store"; + +export type PerformanceData = { + total: Record; + runs: Record[]; +} + +export interface PerformanceStore extends Readable { + startRun(): void; + stopRun(): void; + addPoint(name: string, value?: number): void; + get: () => PerformanceData; +} + +export function createPerformanceStore(): PerformanceStore { + + let data: PerformanceData = { total: {}, runs: [] }; + + let currentRun: Record | undefined; + + let set: (v: PerformanceData) => void; + + const { subscribe } = readable({ total: {}, runs: [] }, (_set) => { + set = _set; + }); + + function startRun() { + currentRun = {}; + } + + function stopRun() { + if (currentRun) { + // Calculate total + Object.keys(currentRun).forEach((name) => { + if (!currentRun?.[name]?.length) return; + let runTotal = currentRun[name].reduce((a, b) => a + b, 0) / currentRun[name].length; + if (!data.total[name]) { + data.total[name] = runTotal; + } else { + data.total[name] = (data.total[name] + runTotal) / 2; + } + }); + + data.runs.push(currentRun); + currentRun = undefined; + if (set) set(data); + } + } + + function addPoint(name: string, value: number) { + if (!currentRun) return; + currentRun[name] = currentRun[name] || []; + currentRun[name].push(value); + } + + function get() { + return data; + } + + return { + subscribe, + startRun, + stopRun, + addPoint, + get + } +} diff --git a/app/src/lib/result-viewer/Scene.svelte b/app/src/lib/result-viewer/Scene.svelte index 4ca8879..36b7983 100644 --- a/app/src/lib/result-viewer/Scene.svelte +++ b/app/src/lib/result-viewer/Scene.svelte @@ -1,5 +1,5 @@ @@ -70,30 +112,32 @@ -{#each geometries as geo} - {#if $AppSettings.showIndices} - {#each geo.attributes.position.array as _, i} - {#if i % 3 === 0} - - {/if} - {/each} - {/if} + + {#each geometries as geo} + {#if $AppSettings.showIndices} + {#each geo.attributes.position.array as _, i} + {#if i % 3 === 0} + + {/if} + {/each} + {/if} - {#if $AppSettings.showVertices} - - - - - {/if} - {#await matcap then value} - - - {#if false} - - {/if} - - {/await} -{/each} + {#if $AppSettings.showVertices} + + + + + {/if} + {#await matcap then value} + + + + {/await} + {/each} + {#if $AppSettings.showStemLines && lines} {#each lines as line} diff --git a/app/src/lib/result-viewer/Viewer.svelte b/app/src/lib/result-viewer/Viewer.svelte index d420f3f..b83c888 100644 --- a/app/src/lib/result-viewer/Viewer.svelte +++ b/app/src/lib/result-viewer/Viewer.svelte @@ -1,36 +1,34 @@ - + diff --git a/app/src/lib/settings/app-settings.ts b/app/src/lib/settings/app-settings.ts index 3e9b489..e25cc72 100644 --- a/app/src/lib/settings/app-settings.ts +++ b/app/src/lib/settings/app-settings.ts @@ -5,7 +5,7 @@ export const AppSettings = localStore("node-settings", { showGrid: true, showNodeGrid: true, snapToGrid: true, - wireframes: false, + wireframe: false, showIndices: false, showVertices: false, centerCamera: true, diff --git a/app/src/lib/worker-runtime-executor-backend.ts b/app/src/lib/worker-runtime-executor-backend.ts index 3074896..6308687 100644 --- a/app/src/lib/worker-runtime-executor-backend.ts +++ b/app/src/lib/worker-runtime-executor-backend.ts @@ -1,7 +1,7 @@ import { MemoryRuntimeExecutor } from "./runtime-executor"; import { RemoteNodeRegistry } from "./node-registry-client"; import type { Graph } from "@nodes/types"; -import { createPerformanceStore } from "./performance"; +import { createPerformanceStore } from "./performance/store"; const nodeRegistry = new RemoteNodeRegistry(""); const executor = new MemoryRuntimeExecutor(nodeRegistry); diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte index b82c3f2..e63bc4f 100644 --- a/app/src/routes/+page.svelte +++ b/app/src/routes/+page.svelte @@ -24,11 +24,14 @@ import Panel from "$lib/settings/Panel.svelte"; import GraphSettings from "$lib/settings/panels/GraphSettings.svelte"; import NestedSettings from "$lib/settings/panels/NestedSettings.svelte"; + import { createPerformanceStore } from "$lib/performance"; + import { type PerformanceData } from "$lib/performance/store"; const nodeRegistry = new RemoteNodeRegistry(""); const workerRuntime = new WorkerRuntimeExecutor(); let performanceData: PerformanceData; + let viewerPerformance = createPerformanceStore(); globalThis.decode = decodeNestedArray; globalThis.encode = encodeNestedArray; @@ -51,15 +54,38 @@ let graphSettings = writable>({}); let graphSettingTypes = {}; - async function handleResult(event: CustomEvent) { - const settings = $graphSettings; - if (!settings) return; + let isWorking = false; + + let unfinished: + | { + graph: Graph; + settings: Record; + } + | undefined; + + async function handleResult(_graph: Graph, _settings: Record) { + if (!_settings) return; + if (isWorking) { + unfinished = { + graph: _graph, + settings: _settings, + }; + return; + } + isWorking = true; try { - res = await workerRuntime.execute(event.detail, settings); + res = await workerRuntime.execute(_graph, _settings); performanceData = await workerRuntime.getPerformanceData(); + isWorking = false; } catch (error) { console.log("errors", error); } + + if (unfinished) { + let d = unfinished; + unfinished = undefined; + handleResult(d.graph, d.settings); + } } $: if (AppSettings) { @@ -69,7 +95,7 @@ }; //@ts-ignore AppSettingTypes.debug.stressTest.loadTree.callback = () => { - graph = templates.tree($AppSettings.amount, $AppSettings.amount); + graph = templates.tree($AppSettings.amount); }; } @@ -82,7 +108,11 @@
- + {#key graph} @@ -96,7 +126,7 @@ snapToGrid={$AppSettings?.snapToGrid} bind:settings={graphSettings} bind:settingTypes={graphSettingTypes} - on:result={handleResult} + on:result={(ev) => handleResult(ev.detail, $graphSettings)} on:save={handleSave} /> @@ -116,7 +146,10 @@ icon="i-tabler-brand-speedtest" > {#if performanceData} - + {/if}