perf: reduce graph load memory and clone overhead

This commit is contained in:
Youzini-afk
2026-04-21 16:56:17 +08:00
parent 076618bc25
commit 4fd4786983
6 changed files with 238 additions and 105 deletions

View File

@@ -297,7 +297,7 @@ function buildCommittedBatchPersistSnapshot(
: null,
rangeEnd,
];
const afterSnapshot = runtime.cloneGraphSnapshot(graph);
const afterSnapshot = graph;
const effectiveArtifacts = Array.isArray(postProcessArtifacts)
? [...postProcessArtifacts]
: [];
@@ -357,17 +357,12 @@ function buildCommittedBatchPersistSnapshot(
persistGraphSnapshot: committedGraphSnapshot,
committedBatchJournalEntry,
afterSnapshot,
committedAfterSnapshot: runtime.cloneGraphSnapshot(committedGraphSnapshot),
committedAfterSnapshot: committedGraphSnapshot,
postProcessArtifacts: effectiveArtifacts,
};
}
function isPersistenceRevisionAccepted(runtime, persistence = null) {
if (!persistence || persistence.accepted === true) return true;
const graphPersistenceState = runtime?.getGraphPersistenceState?.() || {};
if (graphPersistenceState.pendingPersist === true) {
return false;
}
const persistenceRevision = Number(persistence?.revision || 0);
if (!Number.isFinite(persistenceRevision) || persistenceRevision <= 0) {
return false;
@@ -645,7 +640,7 @@ export async function executeExtractionBatchController(
processedRange: [startIdx, endIdx],
postProcessArtifacts: runtime.computePostProcessArtifacts(
beforeSnapshot,
runtime.cloneGraphSnapshot(runtime.getCurrentGraph()),
runtime.getCurrentGraph(),
effects?.postProcessArtifacts || [],
),
vectorHashesInserted: effects?.vectorHashesInserted || [],