Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
perf(GBRA-108): one screening run per screen, so its slices share the Git top level
garrytan409cbb788d45
diff --git a/src/core/persistence/import-reads.ts b/src/core/persistence/import-reads.tsindex 0f85ae0d38..93e4c3dba7 100644--- a/src/core/persistence/import-reads.ts+++ b/src/core/persistence/import-reads.ts@@ -85,7 +85,17 @@ export function importGroupReads(engine: BrainEngine, rows: ReadonlyArray<{ slug};}-const flat = (sql: string) => sql.replace(/\s+/g, ' ').trim();+const flattened = new Map<string, string>();+/** A statement's whitespace-normalized text, remembered for the (bounded) set of statements a screen sends. */+const flat = (sql: string) => {+ let text = flattened.get(sql);+ if (text === undefined) {+ if (flattened.size >= 1024) flattened.clear();+ text = sql.replace(/\s+/g, ' ').trim();+ flattened.set(sql, text);+ }+ return text;+};const ORIGIN = flat(SYNC_ORIGIN_PAGES_SQL), TIMELINE = flat(STORED_TIMELINE_SQL), TAKES = flat(TAKE_COLLISIONS_SQL), FENCE = flat(SAFE_FENCE_SQL);/**diff --git a/src/core/persistence/sync-convergence.ts b/src/core/persistence/sync-convergence.tsindex 62fe94b2d7..fbf17b8066 100644--- a/src/core/persistence/sync-convergence.ts+++ b/src/core/persistence/sync-convergence.ts@@ -194,11 +194,12 @@ const SCREEN_STABLE_READS = [WORKTREE_BINDING_SQL, SOURCE_TRUST_CONFIG_SQL, PAGE* own reads plus a constant, not every shared read once per page.*/export function readOnlySameContentScreen(engine: BrainEngine, context: ManagedSyncContext, processingOptions: SyncProcessingOptions): ConvergenceScreen {+ // One run for all of the screen's calls, so they share its Git top level (sync-prepare.ts `syncGitTopLevel`), read once.+ const runId = randomUUID();return async (level, paths) => {const verdicts = new Map<string, 'same' | 'differs' | 'unknown'>();const authority = await managedSyncAuthority(engine, context.sourceId, context.incarnation, context.root);const committed = level.mode === 'committed' ? await readBlobs(level.gitRoot, [...new Set(paths.map(entry => entry.state.level!).filter(Boolean))], 8 * 1024 * 1024) : new Map<string, Buffer>();- const runId = randomUUID();const pages = importGroupReads(engine, paths.flatMap(entry => entry.slug ? [{ slug: entry.slug, source_id: level.sourceId }] : []), { reread: true });const relative = (entry: ShadowPath) => level.scope ? entry.path.slice(level.scope.length + 1) : entry.path;const origins = paths.flatMap(entry => {