refactor: move debug node into runtime

This commit is contained in:
release-bot
2026-02-12 16:18:29 +01:00
parent ddc3b4ce35
commit da09f8ba1e
4 changed files with 47 additions and 14 deletions

View File

@@ -0,0 +1,23 @@
const data: Record<string, unknown> = {};
export function clearDebugData() {
for (const key in data) {
delete data[key];
}
}
export function getDebugData() {
return { ...data };
}
export const debugNode = {
id: 'max/plantarium/debug',
inputs: {
a: {
type: '*'
}
},
execute(data: Int32Array) {
return data;
}
} as const;

View File

@@ -59,6 +59,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
private definitionMap: Map<string, NodeDefinition> = new Map();
private seed = Math.floor(Math.random() * 100000000);
private debugData: Record<string, Int32Array> = {};
perf?: PerformanceStore;
@@ -139,6 +140,14 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
nodes.push(node);
}
for (const node of graphNodes) {
if (node.type.endsWith('/debug')) {
node.state = node.state || {};
node.state.depth = Math.min(...node.state.parents.map(s => s.state.depth), 1) - 1;
nodes.push(node);
}
}
return [outputNode, nodes] as const;
}
@@ -146,6 +155,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
this.perf?.addPoint('runtime');
let a = performance.now();
this.debugData = {};
// Then we add some metadata to the graph
const [outputNode, nodes] = await this.addMetaData(graph);
@@ -245,6 +255,9 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
log.log(`Inputs:`, inputs);
a = performance.now();
results[node.id] = node_type.execute(encoded_inputs);
if (node_type.id.endsWith('/debug')) {
this.debugData[node.id] = results[node.id];
}
log.log('Executed', node.type, node.id);
b = performance.now();
@@ -273,6 +286,10 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
return res as unknown as Int32Array;
}
getDebugData() {
return this.debugData;
}
getPerformanceData() {
return this.perf?.get();
}

View File

@@ -1,3 +1,4 @@
import { debugNode } from '$lib/node-registry/debugNode';
import { IndexDBCache, RemoteNodeRegistry } from '$lib/node-registry/index';
import type { Graph } from '@nodarium/types';
import { createPerformanceStore } from '@nodarium/utils';
@@ -5,7 +6,7 @@ import { MemoryRuntimeExecutor } from './runtime-executor';
import { MemoryRuntimeCache } from './runtime-executor-cache';
const indexDbCache = new IndexDBCache('node-registry');
const nodeRegistry = new RemoteNodeRegistry('', indexDbCache);
const nodeRegistry = new RemoteNodeRegistry('', indexDbCache, [debugNode]);
const cache = new MemoryRuntimeCache();
const executor = new MemoryRuntimeExecutor(nodeRegistry, cache);
@@ -43,3 +44,7 @@ export async function executeGraph(
export function getPerformanceData() {
return performanceStore.get();
}
export function getDebugData() {
return executor.getDebugData();
}

View File

@@ -4,6 +4,7 @@
import Grid from '$lib/grid';
import { debounceAsyncFunction } from '$lib/helpers';
import { createKeyMap } from '$lib/helpers/createKeyMap';
import { debugNode } from '$lib/node-registry/debugNode.js';
import { IndexDBCache, RemoteNodeRegistry } from '$lib/node-registry/index';
import NodeStore from '$lib/node-store/NodeStore.svelte';
import PerformanceViewer from '$lib/performance/PerformanceViewer.svelte';
@@ -33,19 +34,6 @@
const registryCache = new IndexDBCache('node-registry');
const debugNode = {
id: 'max/plantarium/debug',
inputs: {
a: {
type: '*'
}
},
execute(data: Int32Array) {
console.log({ data });
return data;
}
} as const;
const nodeRegistry = new RemoteNodeRegistry('', registryCache, [debugNode]);
const workerRuntime = new WorkerRuntimeExecutor();
const runtimeCache = new MemoryRuntimeCache();