@valerypopoff/rivet2-core 2.0.10 → 2.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bundle.cjs +211 -106
- package/dist/cjs/bundle.cjs.map +2 -2
- package/dist/esm/api/createProcessor.js +1 -0
- package/dist/esm/model/GraphProcessor.js +219 -105
- package/dist/types/api/createProcessor.d.ts +2 -1
- package/dist/types/model/GraphProcessor.d.ts +5 -0
- package/package.json +1 -1
|
@@ -23,6 +23,7 @@ export function coreCreateProcessor(project, options, internalOptions = {}) {
|
|
|
23
23
|
concurrency: options.concurrency,
|
|
24
24
|
executionPlanCacheMode: internalOptions.executionPlanCacheMode,
|
|
25
25
|
runtimeCache: internalOptions.runtimeCache,
|
|
26
|
+
runtimeProfiler: internalOptions.runtimeProfiler,
|
|
26
27
|
scheduler: internalOptions.scheduler,
|
|
27
28
|
});
|
|
28
29
|
if (options.onStart) {
|
|
@@ -84,6 +84,7 @@ export class GraphProcessor {
|
|
|
84
84
|
#runtimeCache;
|
|
85
85
|
#cacheLoadedProjects;
|
|
86
86
|
#scheduler;
|
|
87
|
+
#runtimeProfiler;
|
|
87
88
|
#captureNodeTimings;
|
|
88
89
|
#useSeededExecutionPlanOnNextRun = false;
|
|
89
90
|
id = nanoid();
|
|
@@ -150,6 +151,38 @@ export class GraphProcessor {
|
|
|
150
151
|
}
|
|
151
152
|
return Math.max(0, getMonotonicTimeMs() - start);
|
|
152
153
|
}
|
|
154
|
+
#startRuntimeProfile() {
|
|
155
|
+
return this.#runtimeProfiler ? getMonotonicTimeMs() : undefined;
|
|
156
|
+
}
|
|
157
|
+
#finishRuntimeProfile(bucket, start) {
|
|
158
|
+
if (start == null || !this.#runtimeProfiler) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
this.#runtimeProfiler.addDuration(bucket, Math.max(0, getMonotonicTimeMs() - start));
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
// Runtime profiling is diagnostic only and must not affect graph execution.
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
#profileRuntimeSync(bucket, run) {
|
|
169
|
+
const start = this.#startRuntimeProfile();
|
|
170
|
+
try {
|
|
171
|
+
return run();
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
this.#finishRuntimeProfile(bucket, start);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async #profileRuntimeAsync(bucket, run) {
|
|
178
|
+
const start = this.#startRuntimeProfile();
|
|
179
|
+
try {
|
|
180
|
+
return await run();
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
this.#finishRuntimeProfile(bucket, start);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
153
186
|
constructor(project, graphId, registry, includeTrace, options) {
|
|
154
187
|
this.#project = project;
|
|
155
188
|
const graph = resolveProcessorGraph(project, graphId);
|
|
@@ -167,6 +200,7 @@ export class GraphProcessor {
|
|
|
167
200
|
this.#runtimeCache = options?.runtimeCache;
|
|
168
201
|
this.#cacheLoadedProjects = options?.cacheLoadedProjects ?? false;
|
|
169
202
|
this.#scheduler = options?.scheduler ?? 'compatible';
|
|
203
|
+
this.#runtimeProfiler = options?.runtimeProfiler;
|
|
170
204
|
this.#captureNodeTimings = options?.captureNodeTimings ?? false;
|
|
171
205
|
this.#emitter.bindMethods(this, ['on', 'off', 'once', 'onAny', 'offAny']);
|
|
172
206
|
this.setExternalFunction('echo', async (value) => ({ type: 'any', value }));
|
|
@@ -179,31 +213,37 @@ export class GraphProcessor {
|
|
|
179
213
|
}
|
|
180
214
|
}
|
|
181
215
|
#preprocessGraph() {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
216
|
+
const profileStart = this.#startRuntimeProfile();
|
|
217
|
+
try {
|
|
218
|
+
const runtimeCache = this.#canUseRuntimeExecutionPlanCache() ? this.#runtimeCache : undefined;
|
|
219
|
+
const shouldUseRuntimeCache = runtimeCache != null;
|
|
220
|
+
const cachedPlan = runtimeCache?.executionPlans?.get(this.#graph);
|
|
221
|
+
if (cachedPlan) {
|
|
222
|
+
this.#applyPreprocessedGraph(cachedPlan, { recreateNodeInstances: true });
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const preprocessedGraph = preprocessGraphState({
|
|
226
|
+
graph: this.#graph,
|
|
227
|
+
loadedProjects: this.#loadedProjects,
|
|
228
|
+
project: this.#project,
|
|
229
|
+
registry: this.#registry,
|
|
230
|
+
warnOnInvalidGraph: this.warnOnInvalidGraph,
|
|
231
|
+
buildExecutionPlan: shouldUseRuntimeCache,
|
|
232
|
+
definitionContext: this.#runtimeCache
|
|
233
|
+
? {
|
|
234
|
+
getGraphBoundary: (project, graphId) => this.#getGraphBoundary(project, graphId),
|
|
235
|
+
}
|
|
236
|
+
: undefined,
|
|
237
|
+
});
|
|
238
|
+
if (shouldUseRuntimeCache && isGraphExecutionPlan(preprocessedGraph)) {
|
|
239
|
+
runtimeCache.executionPlans ??= new WeakMap();
|
|
240
|
+
runtimeCache.executionPlans.set(this.#graph, toReusableGraphExecutionPlan(preprocessedGraph));
|
|
241
|
+
}
|
|
242
|
+
this.#applyPreprocessedGraph(preprocessedGraph);
|
|
188
243
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
loadedProjects: this.#loadedProjects,
|
|
192
|
-
project: this.#project,
|
|
193
|
-
registry: this.#registry,
|
|
194
|
-
warnOnInvalidGraph: this.warnOnInvalidGraph,
|
|
195
|
-
buildExecutionPlan: shouldUseRuntimeCache,
|
|
196
|
-
definitionContext: this.#runtimeCache
|
|
197
|
-
? {
|
|
198
|
-
getGraphBoundary: (project, graphId) => this.#getGraphBoundary(project, graphId),
|
|
199
|
-
}
|
|
200
|
-
: undefined,
|
|
201
|
-
});
|
|
202
|
-
if (shouldUseRuntimeCache && isGraphExecutionPlan(preprocessedGraph)) {
|
|
203
|
-
runtimeCache.executionPlans ??= new WeakMap();
|
|
204
|
-
runtimeCache.executionPlans.set(this.#graph, toReusableGraphExecutionPlan(preprocessedGraph));
|
|
244
|
+
finally {
|
|
245
|
+
this.#finishRuntimeProfile('preprocessGraph', profileStart);
|
|
205
246
|
}
|
|
206
|
-
this.#applyPreprocessedGraph(preprocessedGraph);
|
|
207
247
|
}
|
|
208
248
|
#canUseRuntimeExecutionPlanCache() {
|
|
209
249
|
return this.#canUseRuntimeExecutionPlanCacheFor(this.#project, this.#isSubProcessor);
|
|
@@ -509,32 +549,30 @@ export class GraphProcessor {
|
|
|
509
549
|
throw new Error('Cannot process graph while already processing');
|
|
510
550
|
}
|
|
511
551
|
try {
|
|
512
|
-
this.#initializeGraphRun(context, inputs, contextValues);
|
|
513
|
-
await this.#loadProjectReferences();
|
|
514
|
-
this.#prepareNodeProcessContextBase();
|
|
552
|
+
this.#profileRuntimeSync('initializeGraphRun', () => this.#initializeGraphRun(context, inputs, contextValues));
|
|
553
|
+
await this.#profileRuntimeAsync('loadProjectReferences', () => this.#loadProjectReferences());
|
|
554
|
+
this.#profileRuntimeSync('prepareNodeProcessContextBase', () => this.#prepareNodeProcessContextBase());
|
|
515
555
|
const shouldUseSeededExecutionPlan = this.#seededExecutionPlanForNextRun() != null;
|
|
516
556
|
this.#useSeededExecutionPlanOnNextRun = false;
|
|
517
557
|
if (!shouldUseSeededExecutionPlan) {
|
|
518
558
|
this.#preprocessGraph();
|
|
519
559
|
}
|
|
520
|
-
await this.#emitGraphStart();
|
|
521
|
-
await this.#emitPreloadedNodeResults();
|
|
522
|
-
await this.#waitUntilUnpaused();
|
|
560
|
+
await this.#profileRuntimeAsync('emitGraphStart', () => this.#emitGraphStart());
|
|
561
|
+
await this.#profileRuntimeAsync('emitPreloadedNodeResults', () => this.#emitPreloadedNodeResults());
|
|
562
|
+
await this.#profileRuntimeAsync('waitUntilUnpaused', () => this.#waitUntilUnpaused());
|
|
523
563
|
if (this.#canUseFastAcyclicScheduler()) {
|
|
524
|
-
await this.#processFastAcyclicGraph();
|
|
564
|
+
await this.#profileRuntimeAsync('processFastAcyclicGraph', () => this.#processFastAcyclicGraph());
|
|
525
565
|
}
|
|
526
566
|
else {
|
|
527
|
-
await this.#
|
|
528
|
-
await this.#processingQueue.onIdle();
|
|
529
|
-
this.#markUnqueuedNodesIgnored();
|
|
567
|
+
await this.#profileRuntimeAsync('processCompatibleGraph', () => this.#processCompatibleGraph());
|
|
530
568
|
}
|
|
531
|
-
await this.#throwIfGraphErrored();
|
|
532
|
-
return await this.#finalizeGraphRun();
|
|
569
|
+
await this.#profileRuntimeAsync('throwIfGraphErrored', () => this.#throwIfGraphErrored());
|
|
570
|
+
return await this.#profileRuntimeAsync('finalizeGraphRun', () => this.#finalizeGraphRun());
|
|
533
571
|
}
|
|
534
572
|
finally {
|
|
535
573
|
this.#running = false;
|
|
536
574
|
this.#cleanupTokenizerErrorListener();
|
|
537
|
-
await this.#emitFinishIfNeeded();
|
|
575
|
+
await this.#profileRuntimeAsync('emitFinish', () => this.#emitFinishIfNeeded());
|
|
538
576
|
}
|
|
539
577
|
}
|
|
540
578
|
async #emitFinishIfNeeded() {
|
|
@@ -641,6 +679,11 @@ export class GraphProcessor {
|
|
|
641
679
|
});
|
|
642
680
|
}
|
|
643
681
|
}
|
|
682
|
+
async #processCompatibleGraph() {
|
|
683
|
+
await this.#queueStartNodes(getStartNodes(this.#executionState, this.#graph.nodes, this.runToNodeIds));
|
|
684
|
+
await this.#processingQueue.onIdle();
|
|
685
|
+
this.#markUnqueuedNodesIgnored();
|
|
686
|
+
}
|
|
644
687
|
#canUseFastAcyclicScheduler() {
|
|
645
688
|
if (this.#scheduler !== 'fast-acyclic') {
|
|
646
689
|
return false;
|
|
@@ -662,14 +705,29 @@ export class GraphProcessor {
|
|
|
662
705
|
});
|
|
663
706
|
}
|
|
664
707
|
async #processFastAcyclicGraph() {
|
|
708
|
+
const relevantNodeIds = new Set();
|
|
709
|
+
const nodesToVisit = [...getStartNodes(this.#executionState, this.#graph.nodes)];
|
|
710
|
+
for (let index = 0; index < nodesToVisit.length; index += 1) {
|
|
711
|
+
const node = nodesToVisit[index];
|
|
712
|
+
if (relevantNodeIds.has(node.id)) {
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
relevantNodeIds.add(node.id);
|
|
716
|
+
nodesToVisit.push(...getInputNodesTo(this.#executionState, node));
|
|
717
|
+
}
|
|
718
|
+
const inputNodeIdsByNode = new Map();
|
|
665
719
|
const remainingInputsByNode = new Map();
|
|
666
720
|
const readyNodes = [];
|
|
667
721
|
const queuedNodeIds = new Set();
|
|
668
722
|
for (const node of this.#graph.nodes) {
|
|
723
|
+
if (!relevantNodeIds.has(node.id)) {
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
669
726
|
const inputNodeIds = new Set();
|
|
670
727
|
for (const inputNode of getInputNodesTo(this.#executionState, node)) {
|
|
671
728
|
inputNodeIds.add(inputNode.id);
|
|
672
729
|
}
|
|
730
|
+
inputNodeIdsByNode.set(node.id, inputNodeIds);
|
|
673
731
|
const inputCount = inputNodeIds.size;
|
|
674
732
|
remainingInputsByNode.set(node.id, inputCount);
|
|
675
733
|
if (inputCount === 0) {
|
|
@@ -680,8 +738,11 @@ export class GraphProcessor {
|
|
|
680
738
|
await new Promise((resolve, reject) => {
|
|
681
739
|
let activeCount = 0;
|
|
682
740
|
let settled = false;
|
|
683
|
-
const queueReadyOutputs = (outputNodes) => {
|
|
741
|
+
const queueReadyOutputs = (node, outputNodes) => {
|
|
684
742
|
for (const outputNode of outputNodes) {
|
|
743
|
+
if (!relevantNodeIds.has(outputNode.id) || !inputNodeIdsByNode.get(outputNode.id)?.has(node.id)) {
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
685
746
|
const remainingInputs = (remainingInputsByNode.get(outputNode.id) ?? 0) - 1;
|
|
686
747
|
remainingInputsByNode.set(outputNode.id, remainingInputs);
|
|
687
748
|
if (remainingInputs <= 0 && !queuedNodeIds.has(outputNode.id)) {
|
|
@@ -707,7 +768,7 @@ export class GraphProcessor {
|
|
|
707
768
|
const node = readyNodes.shift();
|
|
708
769
|
activeCount += 1;
|
|
709
770
|
void this.#processNodeIfAllInputsAvailable(node, { queueOutputNodes: false })
|
|
710
|
-
.then(queueReadyOutputs)
|
|
771
|
+
.then((outputNodes) => queueReadyOutputs(node, outputNodes))
|
|
711
772
|
.then(() => {
|
|
712
773
|
activeCount -= 1;
|
|
713
774
|
pump();
|
|
@@ -826,46 +887,56 @@ export class GraphProcessor {
|
|
|
826
887
|
}
|
|
827
888
|
}
|
|
828
889
|
async #fetchNodeDataAndProcessNode(node) {
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
890
|
+
const profileStart = this.#startRuntimeProfile();
|
|
891
|
+
try {
|
|
892
|
+
if (this.#currentlyProcessing.has(node.id) || this.#queuedNodes.has(node.id)) {
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
if (this.#nodeResults.has(node.id) || this.#erroredNodes.has(node.id)) {
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
const inputNodesProfileStart = this.#startRuntimeProfile();
|
|
899
|
+
const inputNodes = getInputNodesTo(this.#executionState, node);
|
|
900
|
+
this.#finishRuntimeProfile('getInputNodesTo', inputNodesProfileStart);
|
|
901
|
+
if (this.#hasErroredInputNode(node, inputNodes)) {
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
this.#emitTraceEvent(`Node ${node.title} has input nodes: ${inputNodes.map((n) => n.title).join(', ')}`);
|
|
905
|
+
const attachedData = this.#getAttachedDataTo(node);
|
|
906
|
+
if (node.type === 'raceInputs' || attachedData.races) {
|
|
907
|
+
for (const inputNode of inputNodes) {
|
|
908
|
+
const inputNodeAttachedData = this.#getAttachedDataTo(inputNode);
|
|
909
|
+
const raceIds = new Set([...(attachedData.races?.raceIds ?? [])]);
|
|
910
|
+
if (node.type === 'raceInputs') {
|
|
911
|
+
raceIds.add(`race-${node.id}`);
|
|
912
|
+
}
|
|
913
|
+
inputNodeAttachedData.races = {
|
|
914
|
+
propagate: false,
|
|
915
|
+
raceIds: [...raceIds],
|
|
916
|
+
completed: false,
|
|
917
|
+
};
|
|
847
918
|
}
|
|
848
|
-
inputNodeAttachedData.races = {
|
|
849
|
-
propagate: false,
|
|
850
|
-
raceIds: [...raceIds],
|
|
851
|
-
completed: false,
|
|
852
|
-
};
|
|
853
919
|
}
|
|
920
|
+
this.#queuedNodes.add(node.id);
|
|
921
|
+
void this.#processingQueue.addAll(inputNodes.map((inputNode) => {
|
|
922
|
+
return async () => {
|
|
923
|
+
this.#emitTraceEvent(`Fetching required data for node ${inputNode.title} (${inputNode.id})`);
|
|
924
|
+
await this.#fetchNodeDataAndProcessNode(inputNode);
|
|
925
|
+
};
|
|
926
|
+
}));
|
|
927
|
+
await this.#processNodeIfAllInputsAvailable(node);
|
|
928
|
+
}
|
|
929
|
+
finally {
|
|
930
|
+
this.#finishRuntimeProfile('fetchNodeDataAndProcessNode', profileStart);
|
|
854
931
|
}
|
|
855
|
-
this.#queuedNodes.add(node.id);
|
|
856
|
-
void this.#processingQueue.addAll(inputNodes.map((inputNode) => {
|
|
857
|
-
return async () => {
|
|
858
|
-
this.#emitTraceEvent(`Fetching required data for node ${inputNode.title} (${inputNode.id})`);
|
|
859
|
-
await this.#fetchNodeDataAndProcessNode(inputNode);
|
|
860
|
-
};
|
|
861
|
-
}));
|
|
862
|
-
await this.#processNodeIfAllInputsAvailable(node);
|
|
863
932
|
}
|
|
864
933
|
/** If all inputs are present, all conditions met, processes the node. */
|
|
865
934
|
async #processNodeIfAllInputsAvailable(node, options = {}) {
|
|
866
935
|
const { queueOutputNodes = true } = options;
|
|
867
936
|
const builtInNode = node;
|
|
937
|
+
const inputNodesProfileStart = this.#startRuntimeProfile();
|
|
868
938
|
const inputNodes = getInputNodesTo(this.#executionState, node);
|
|
939
|
+
this.#finishRuntimeProfile('getInputNodesTo', inputNodesProfileStart);
|
|
869
940
|
if (this.#shouldSkipNodeProcessing(node, inputNodes)) {
|
|
870
941
|
return [];
|
|
871
942
|
}
|
|
@@ -873,7 +944,9 @@ export class GraphProcessor {
|
|
|
873
944
|
if (this.#shouldSkipCompletedRaceNode(node, attachedData)) {
|
|
874
945
|
return [];
|
|
875
946
|
}
|
|
947
|
+
const inputValuesProfileStart = this.#startRuntimeProfile();
|
|
876
948
|
const inputValues = this.#getInputValuesForNode(node);
|
|
949
|
+
this.#finishRuntimeProfile('getInputValuesForNode', inputValuesProfileStart);
|
|
877
950
|
const loopExclusion = this.#excludedDueToControlFlow(node, inputValues, nanoid(), LOOP_NOT_BROKEN_SENTINEL, { queueOutputNodes });
|
|
878
951
|
if (loopExclusion) {
|
|
879
952
|
this.#emitTraceEvent(`Node ${node.title} is excluded due to control flow`);
|
|
@@ -898,7 +971,14 @@ export class GraphProcessor {
|
|
|
898
971
|
if (this.#beginNodeProcessing(node, attachedData) === false) {
|
|
899
972
|
return [];
|
|
900
973
|
}
|
|
901
|
-
const
|
|
974
|
+
const processProfileStart = this.#startRuntimeProfile();
|
|
975
|
+
let processResult;
|
|
976
|
+
try {
|
|
977
|
+
processResult = await this.#processNode(node);
|
|
978
|
+
}
|
|
979
|
+
finally {
|
|
980
|
+
this.#finishRuntimeProfile('nodeDispatch', processProfileStart);
|
|
981
|
+
}
|
|
902
982
|
const { processId } = processResult;
|
|
903
983
|
if (this.slowMode) {
|
|
904
984
|
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
@@ -907,7 +987,9 @@ export class GraphProcessor {
|
|
|
907
987
|
this.#visitedNodes.add(node.id);
|
|
908
988
|
this.#currentlyProcessing.delete(node.id);
|
|
909
989
|
this.#remainingNodes.delete(node.id);
|
|
990
|
+
const outputNodesProfileStart = this.#startRuntimeProfile();
|
|
910
991
|
const outputNodes = getOutputNodesFrom(this.#executionState, node);
|
|
992
|
+
this.#finishRuntimeProfile('getOutputNodesFrom', outputNodesProfileStart);
|
|
911
993
|
this.#handleLoopControllerPostProcess(node, attachedData);
|
|
912
994
|
this.#handleCompletedRace(node);
|
|
913
995
|
const childLoopInfoError = this.#assignChildLoopInfo(node, builtInNode, attachedData);
|
|
@@ -917,7 +999,9 @@ export class GraphProcessor {
|
|
|
917
999
|
}
|
|
918
1000
|
this.#propagateAttachedDataToOutputNodes(node, attachedData, outputNodes.connectionsToNodes);
|
|
919
1001
|
if (queueOutputNodes && processResult.shouldQueueOutputNodes) {
|
|
1002
|
+
const queueOutputsProfileStart = this.#startRuntimeProfile();
|
|
920
1003
|
this.#queueOutputNodes(node, outputNodes.nodes);
|
|
1004
|
+
this.#finishRuntimeProfile('queueOutputNodes', queueOutputsProfileStart);
|
|
921
1005
|
}
|
|
922
1006
|
return processResult.shouldQueueOutputNodes ? outputNodes.nodes : [];
|
|
923
1007
|
}
|
|
@@ -1108,7 +1192,9 @@ export class GraphProcessor {
|
|
|
1108
1192
|
});
|
|
1109
1193
|
}
|
|
1110
1194
|
async #processNormalNode(node, processId) {
|
|
1195
|
+
const inputValuesProfileStart = this.#startRuntimeProfile();
|
|
1111
1196
|
const inputValues = this.#getInputValuesForNode(node);
|
|
1197
|
+
this.#finishRuntimeProfile('getInputValuesForNode', inputValuesProfileStart);
|
|
1112
1198
|
if (this.#excludedDueToControlFlow(node, inputValues, processId)) {
|
|
1113
1199
|
return;
|
|
1114
1200
|
}
|
|
@@ -1253,11 +1339,19 @@ export class GraphProcessor {
|
|
|
1253
1339
|
if (this.#abortController.signal.aborted) {
|
|
1254
1340
|
nodeAbortController.abort(getAbortSignalReason(this.#abortController.signal));
|
|
1255
1341
|
}
|
|
1342
|
+
const createContextProfileStart = this.#startRuntimeProfile();
|
|
1256
1343
|
const context = this.#createNodeProcessContext(node, inputValues, index, processId, nodeAbortController, partialOutput);
|
|
1344
|
+
this.#finishRuntimeProfile('createNodeProcessContext', createContextProfileStart);
|
|
1257
1345
|
let results;
|
|
1258
1346
|
try {
|
|
1259
1347
|
await this.#waitUntilUnpaused();
|
|
1260
|
-
|
|
1348
|
+
const implementationProfileStart = this.#startRuntimeProfile();
|
|
1349
|
+
try {
|
|
1350
|
+
results = await instance.process(inputValues, context);
|
|
1351
|
+
}
|
|
1352
|
+
finally {
|
|
1353
|
+
this.#finishRuntimeProfile('nodeImplementation', implementationProfileStart);
|
|
1354
|
+
}
|
|
1261
1355
|
}
|
|
1262
1356
|
finally {
|
|
1263
1357
|
this.#unregisterNodeAbortController(node.id, nodeAbortController);
|
|
@@ -1338,15 +1432,23 @@ export class GraphProcessor {
|
|
|
1338
1432
|
const initialExecutionPlan = subprocessorGraph && this.#canUseRuntimeExecutionPlanCacheFor(subprocessorProject, true)
|
|
1339
1433
|
? this.#runtimeCache?.executionPlans?.get(subprocessorGraph)
|
|
1340
1434
|
: undefined;
|
|
1341
|
-
const
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1435
|
+
const createProfileStart = this.#startRuntimeProfile();
|
|
1436
|
+
let processor;
|
|
1437
|
+
try {
|
|
1438
|
+
processor = new GraphProcessor(subprocessorProject, subGraphId, this.#registry, this.#includeTrace, {
|
|
1439
|
+
cacheLoadedProjects: this.#cacheLoadedProjects,
|
|
1440
|
+
captureNodeTimings: this.#captureNodeTimings,
|
|
1441
|
+
concurrency: this.#concurrency,
|
|
1442
|
+
executionPlanCacheMode: this.#executionPlanCacheMode,
|
|
1443
|
+
initialExecutionPlan,
|
|
1444
|
+
runtimeCache: this.#runtimeCache,
|
|
1445
|
+
runtimeProfiler: this.#runtimeProfiler,
|
|
1446
|
+
scheduler: this.#scheduler,
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1449
|
+
finally {
|
|
1450
|
+
this.#finishRuntimeProfile('createSubProcessor', createProfileStart);
|
|
1451
|
+
}
|
|
1350
1452
|
processor.executor = this.executor;
|
|
1351
1453
|
processor.#isSubProcessor = true;
|
|
1352
1454
|
processor.#executionCache = this.#executionCache;
|
|
@@ -1360,32 +1462,44 @@ export class GraphProcessor {
|
|
|
1360
1462
|
index,
|
|
1361
1463
|
processId,
|
|
1362
1464
|
};
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1465
|
+
const wireEventsProfileStart = this.#startRuntimeProfile();
|
|
1466
|
+
try {
|
|
1467
|
+
wireSubprocessorEvents(processor, this.#emitter, {
|
|
1468
|
+
isPaused: () => this.#isPaused,
|
|
1469
|
+
pause: () => {
|
|
1470
|
+
void this.pause();
|
|
1471
|
+
},
|
|
1472
|
+
resume: () => {
|
|
1473
|
+
void this.resume();
|
|
1474
|
+
},
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
finally {
|
|
1478
|
+
this.#finishRuntimeProfile('wireSubProcessorEvents', wireEventsProfileStart);
|
|
1479
|
+
}
|
|
1372
1480
|
this.#subprocessors.add(processor);
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
this.
|
|
1378
|
-
|
|
1379
|
-
this.
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
this.
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1481
|
+
const wireLifecycleProfileStart = this.#startRuntimeProfile();
|
|
1482
|
+
try {
|
|
1483
|
+
wireSubprocessorLifecycle(processor, {
|
|
1484
|
+
signal,
|
|
1485
|
+
parentAbortSignal: this.#abortController.signal,
|
|
1486
|
+
onParentPause: (listener) => {
|
|
1487
|
+
this.on('pause', listener);
|
|
1488
|
+
return () => {
|
|
1489
|
+
this.off('pause', listener);
|
|
1490
|
+
};
|
|
1491
|
+
},
|
|
1492
|
+
onParentResume: (listener) => {
|
|
1493
|
+
this.on('resume', listener);
|
|
1494
|
+
return () => {
|
|
1495
|
+
this.off('resume', listener);
|
|
1496
|
+
};
|
|
1497
|
+
},
|
|
1498
|
+
});
|
|
1499
|
+
}
|
|
1500
|
+
finally {
|
|
1501
|
+
this.#finishRuntimeProfile('wireSubProcessorLifecycle', wireLifecycleProfileStart);
|
|
1502
|
+
}
|
|
1389
1503
|
return processor;
|
|
1390
1504
|
}
|
|
1391
1505
|
async #requestUserInput(node, inputStrings, inputValues, renderingType, processId) {
|
|
@@ -3,7 +3,7 @@ import type { AttachedData } from '../utils/serialization/serializationUtils.js'
|
|
|
3
3
|
import type { AudioProvider } from '../integrations/AudioProvider.js';
|
|
4
4
|
import type { DataValue } from '../model/DataValue.js';
|
|
5
5
|
import type { DatasetProvider } from '../integrations/DatasetProvider.js';
|
|
6
|
-
import type { ExternalFunction, GraphProcessorConcurrency, GraphProcessorExecutionPlanCacheMode, GraphProcessorRuntimeCache, GraphProcessorScheduler, ProcessEvents } from '../model/GraphProcessor.js';
|
|
6
|
+
import type { ExternalFunction, GraphProcessorConcurrency, GraphProcessorExecutionPlanCacheMode, GraphProcessorRuntimeCache, GraphProcessorRuntimeProfiler, GraphProcessorScheduler, ProcessEvents } from '../model/GraphProcessor.js';
|
|
7
7
|
import type { Project } from '../model/Project.js';
|
|
8
8
|
import type { MCPProvider } from '../integrations/mcp/MCPProvider.js';
|
|
9
9
|
import type { NativeApi } from '../native/NativeApi.js';
|
|
@@ -47,6 +47,7 @@ export type CoreCreateProcessorInternalOptions = {
|
|
|
47
47
|
cacheLoadedProjects?: boolean;
|
|
48
48
|
executionPlanCacheMode?: GraphProcessorExecutionPlanCacheMode;
|
|
49
49
|
runtimeCache?: GraphProcessorRuntimeCache;
|
|
50
|
+
runtimeProfiler?: GraphProcessorRuntimeProfiler;
|
|
50
51
|
scheduler?: GraphProcessorScheduler;
|
|
51
52
|
};
|
|
52
53
|
export declare function coreCreateProcessor(project: Project, options: RunGraphOptions, internalOptions?: CoreCreateProcessorInternalOptions): {
|
|
@@ -153,6 +153,10 @@ export type GraphProcessorRuntimeCache = {
|
|
|
153
153
|
};
|
|
154
154
|
export type GraphProcessorExecutionPlanCacheMode = 'all' | 'subprocessors';
|
|
155
155
|
export type GraphProcessorScheduler = 'compatible' | 'fast-acyclic';
|
|
156
|
+
export type GraphProcessorRuntimeProfileBucket = 'initializeGraphRun' | 'loadProjectReferences' | 'prepareNodeProcessContextBase' | 'preprocessGraph' | 'emitGraphStart' | 'emitPreloadedNodeResults' | 'waitUntilUnpaused' | 'processFastAcyclicGraph' | 'processCompatibleGraph' | 'throwIfGraphErrored' | 'finalizeGraphRun' | 'emitFinish' | 'fetchNodeDataAndProcessNode' | 'getInputNodesTo' | 'getInputValuesForNode' | 'nodeDispatch' | 'nodeImplementation' | 'createNodeProcessContext' | 'getOutputNodesFrom' | 'queueOutputNodes' | 'createSubProcessor' | 'wireSubProcessorEvents' | 'wireSubProcessorLifecycle';
|
|
157
|
+
export type GraphProcessorRuntimeProfiler = {
|
|
158
|
+
addDuration: (bucket: GraphProcessorRuntimeProfileBucket, durationMs: number) => void;
|
|
159
|
+
};
|
|
156
160
|
export declare const DEFAULT_SPLIT_RUN_CONCURRENCY = 4;
|
|
157
161
|
export type RaceId = Tagged<string, 'RaceId'>;
|
|
158
162
|
export type LoopInfo = AttachedNodeDataItem & {
|
|
@@ -194,6 +198,7 @@ export declare class GraphProcessor {
|
|
|
194
198
|
executionPlanCacheMode?: GraphProcessorExecutionPlanCacheMode;
|
|
195
199
|
initialExecutionPlan?: GraphExecutionPlan;
|
|
196
200
|
runtimeCache?: GraphProcessorRuntimeCache;
|
|
201
|
+
runtimeProfiler?: GraphProcessorRuntimeProfiler;
|
|
197
202
|
scheduler?: GraphProcessorScheduler;
|
|
198
203
|
});
|
|
199
204
|
on: Emittery<ProcessEvents>["on"];
|