@colbymchenry/codegraph-win32-x64 1.3.0 → 1.4.0

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.
Files changed (68) hide show
  1. package/lib/dist/db/index.d.ts +64 -5
  2. package/lib/dist/db/index.d.ts.map +1 -1
  3. package/lib/dist/db/index.js +170 -12
  4. package/lib/dist/db/index.js.map +1 -1
  5. package/lib/dist/db/queries.d.ts +25 -1
  6. package/lib/dist/db/queries.d.ts.map +1 -1
  7. package/lib/dist/db/queries.js +39 -0
  8. package/lib/dist/db/queries.js.map +1 -1
  9. package/lib/dist/db/wal-valve.d.ts +106 -0
  10. package/lib/dist/db/wal-valve.d.ts.map +1 -0
  11. package/lib/dist/db/wal-valve.js +208 -0
  12. package/lib/dist/db/wal-valve.js.map +1 -0
  13. package/lib/dist/extraction/grammars.d.ts +16 -1
  14. package/lib/dist/extraction/grammars.d.ts.map +1 -1
  15. package/lib/dist/extraction/grammars.js +85 -43
  16. package/lib/dist/extraction/grammars.js.map +1 -1
  17. package/lib/dist/extraction/index.d.ts +1 -1
  18. package/lib/dist/extraction/index.d.ts.map +1 -1
  19. package/lib/dist/extraction/index.js +113 -37
  20. package/lib/dist/extraction/index.js.map +1 -1
  21. package/lib/dist/extraction/parse-pool.d.ts +27 -1
  22. package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
  23. package/lib/dist/extraction/parse-pool.js +75 -7
  24. package/lib/dist/extraction/parse-pool.js.map +1 -1
  25. package/lib/dist/extraction/parse-worker.js +9 -2
  26. package/lib/dist/extraction/parse-worker.js.map +1 -1
  27. package/lib/dist/index.d.ts.map +1 -1
  28. package/lib/dist/index.js +70 -4
  29. package/lib/dist/index.js.map +1 -1
  30. package/lib/dist/mcp/daemon.d.ts.map +1 -1
  31. package/lib/dist/mcp/daemon.js +23 -1
  32. package/lib/dist/mcp/daemon.js.map +1 -1
  33. package/lib/dist/mcp/proxy.d.ts.map +1 -1
  34. package/lib/dist/mcp/proxy.js +8 -0
  35. package/lib/dist/mcp/proxy.js.map +1 -1
  36. package/lib/dist/mcp/query-pool.d.ts +14 -0
  37. package/lib/dist/mcp/query-pool.d.ts.map +1 -1
  38. package/lib/dist/mcp/query-pool.js +18 -0
  39. package/lib/dist/mcp/query-pool.js.map +1 -1
  40. package/lib/dist/mcp/session.d.ts.map +1 -1
  41. package/lib/dist/mcp/session.js +6 -0
  42. package/lib/dist/mcp/session.js.map +1 -1
  43. package/lib/dist/mcp/tools.d.ts.map +1 -1
  44. package/lib/dist/mcp/tools.js +14 -9
  45. package/lib/dist/mcp/tools.js.map +1 -1
  46. package/lib/dist/mcp/transport.d.ts.map +1 -1
  47. package/lib/dist/mcp/transport.js +18 -0
  48. package/lib/dist/mcp/transport.js.map +1 -1
  49. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts +2 -1
  50. package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
  51. package/lib/dist/resolution/c-fnptr-synthesizer.js +170 -146
  52. package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
  53. package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
  54. package/lib/dist/resolution/callback-synthesizer.js +381 -101
  55. package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
  56. package/lib/dist/resolution/goframe-synthesizer.d.ts +2 -1
  57. package/lib/dist/resolution/goframe-synthesizer.d.ts.map +1 -1
  58. package/lib/dist/resolution/goframe-synthesizer.js +8 -3
  59. package/lib/dist/resolution/goframe-synthesizer.js.map +1 -1
  60. package/lib/dist/resolution/index.d.ts +10 -0
  61. package/lib/dist/resolution/index.d.ts.map +1 -1
  62. package/lib/dist/resolution/index.js +55 -15
  63. package/lib/dist/resolution/index.js.map +1 -1
  64. package/lib/dist/resolution/types.d.ts +9 -0
  65. package/lib/dist/resolution/types.d.ts.map +1 -1
  66. package/lib/node_modules/.package-lock.json +1 -1
  67. package/lib/package.json +1 -1
  68. package/package.json +1 -1
@@ -40,6 +40,15 @@ const CC_DISPATCH_RE = /(\w+)\.forEach\s*\{\s*(?:\$0|it)\s*\(/g;
40
40
  const CC_APPEND_WRITE_RE = /(\w+)\.write\s*\{\s*\$0(?:\.(\w+))?\.(?:append|add|push|insert)\s*\(/g;
41
41
  const CC_APPEND_DIRECT_RE = /(\w+)\.(?:append|add|push|insert)\s*\(/g;
42
42
  const CC_FANOUT_CAP = 8; // skip a field name with more dispatchers/registrars than this (too generic to pair confidently)
43
+ // The dispatcher gate — `{ $0( ` / `{ it( ` element-invocation — is Swift/Kotlin
44
+ // trailing-closure syntax, so ONLY those languages can ever contribute a
45
+ // dispatcher, and a cross-language registrar pairing (a JS `.push(` against a
46
+ // Swift dispatcher's field name) would be a wrong edge, not a missed one.
47
+ // Gating both sides here isn't just precision: `.push(`/`.add(` is everywhere
48
+ // in JS/PHP, so an ungated scan slices + regexes nearly every function on repos
49
+ // where the pass cannot emit a single edge — on a 12k-file PHP/JS app that was
50
+ // 20+ minutes of the "Resolving refs" tail and a #850 watchdog kill (#1235).
51
+ const CC_LANGUAGES = new Set(['swift', 'kotlin']);
43
52
  function kebabToPascal(s) {
44
53
  return s.split('-').map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join('');
45
54
  }
@@ -75,6 +84,35 @@ function sliceLines(content, startLine, endLine) {
75
84
  return null;
76
85
  return content.split('\n').slice(startLine - 1, endLine).join('\n');
77
86
  }
87
+ /**
88
+ * Per-match line resolver over `src`, 1-based at `baseLine`. The inline
89
+ * `src.slice(0, idx).split('\n').length` idiom is O(source-length) PER MATCH,
90
+ * which goes quadratic on a match-dense source (a generated function full of
91
+ * `.push(` calls re-scanned tens of thousands of times was most of the #1235
92
+ * indexing wedge). Builds the newline index once — lazily, since most sources
93
+ * never produce a match — then answers each call with a binary search.
94
+ */
95
+ function makeLineAt(src, baseLine) {
96
+ let nl = null;
97
+ return (idx) => {
98
+ if (!nl) {
99
+ nl = [];
100
+ for (let i = src.indexOf('\n'); i !== -1; i = src.indexOf('\n', i + 1))
101
+ nl.push(i);
102
+ }
103
+ // Count newlines strictly before idx.
104
+ let lo = 0;
105
+ let hi = nl.length;
106
+ while (lo < hi) {
107
+ const mid = (lo + hi) >> 1;
108
+ if (nl[mid] < idx)
109
+ lo = mid + 1;
110
+ else
111
+ hi = mid;
112
+ }
113
+ return baseLine + lo;
114
+ };
115
+ }
78
116
  function registrarField(src) {
79
117
  const m = src.match(/this\.(\w+)\.(?:add|push|set)\(/);
80
118
  return m ? m[1] : null;
@@ -212,13 +250,18 @@ async function closureCollectionEdges(queries, ctx, onYield) {
212
250
  arr.push({ node, line: absLine });
213
251
  registrars.set(field, arr);
214
252
  };
215
- // Slices EVERY method/function's source (no cheap name-gate), so on a repo
216
- // with a huge file this is the heaviest synthesis pass — yield mid-scan so it
217
- // can't wedge the #850 watchdog on its own (#1091).
253
+ // Slices EVERY Swift/Kotlin method/function's source (no cheap name-gate), so
254
+ // on a repo with a huge file this is the heaviest synthesis pass — yield
255
+ // mid-scan (and mid-match-loop below: a single generated function dense with
256
+ // matches must not starve the watchdog either) so it can't wedge the #850
257
+ // watchdog on its own (#1091, #1235).
218
258
  let scanned = 0;
259
+ let matchTick = 0;
219
260
  for (const m of methodAndFunctionNodes(queries)) {
220
261
  if ((++scanned & 127) === 0)
221
262
  await onYield();
263
+ if (!CC_LANGUAGES.has(m.language))
264
+ continue;
222
265
  const content = ctx.readFile(m.filePath);
223
266
  const src = content && sliceLines(content, m.startLine, m.endLine);
224
267
  if (!src)
@@ -227,11 +270,13 @@ async function closureCollectionEdges(queries, ctx, onYield) {
227
270
  const hasAppend = src.includes('.append(') || src.includes('.add(') || src.includes('.push(') || src.includes('.insert(');
228
271
  if (!hasForEach && !hasAppend)
229
272
  continue;
230
- const lineAt = (idx) => (m.startLine ?? 1) + src.slice(0, idx).split('\n').length - 1;
273
+ const lineAt = makeLineAt(src, m.startLine ?? 1);
231
274
  if (hasForEach) {
232
275
  CC_DISPATCH_RE.lastIndex = 0;
233
276
  let d;
234
277
  while ((d = CC_DISPATCH_RE.exec(src))) {
278
+ if ((++matchTick & 255) === 0)
279
+ await onYield();
235
280
  const arr = dispatchers.get(d[1]) ?? [];
236
281
  if (!arr.some((n) => n.node.id === m.id))
237
282
  arr.push({ node: m, line: lineAt(d.index) });
@@ -241,12 +286,18 @@ async function closureCollectionEdges(queries, ctx, onYield) {
241
286
  if (hasAppend) {
242
287
  CC_APPEND_WRITE_RE.lastIndex = 0;
243
288
  let w;
244
- while ((w = CC_APPEND_WRITE_RE.exec(src)))
289
+ while ((w = CC_APPEND_WRITE_RE.exec(src))) {
290
+ if ((++matchTick & 255) === 0)
291
+ await onYield();
245
292
  addReg(w[2] || w[1], m, lineAt(w.index)); // nested `$0.streams` else the `.write` receiver
293
+ }
246
294
  CC_APPEND_DIRECT_RE.lastIndex = 0;
247
295
  let a;
248
- while ((a = CC_APPEND_DIRECT_RE.exec(src)))
296
+ while ((a = CC_APPEND_DIRECT_RE.exec(src))) {
297
+ if ((++matchTick & 255) === 0)
298
+ await onYield();
249
299
  addReg(a[1], m, lineAt(a.index));
300
+ }
250
301
  }
251
302
  }
252
303
  const edges = [];
@@ -276,10 +327,13 @@ async function closureCollectionEdges(queries, ctx, onYield) {
276
327
  }
277
328
  /** Phase 2: string-keyed EventEmitter channels (on('e', fn) ↔ emit('e')). */
278
329
  async function eventEmitterEdges(ctx, onYield) {
330
+ let scannedFiles = 0;
279
331
  const emitsByEvent = new Map(); // event → dispatcher node ids
280
332
  const handlersByEvent = new Map(); // event → handler id → registration site (file:line)
281
333
  let scanned = 0;
282
334
  for (const file of ctx.getAllFiles()) {
335
+ if ((++scannedFiles & 15) === 0)
336
+ await onYield();
283
337
  if ((++scanned & 255) === 0)
284
338
  await onYield(); // #1091: yield mid-scan on huge graphs
285
339
  const content = ctx.readFile(file);
@@ -290,7 +344,7 @@ async function eventEmitterEdges(ctx, onYield) {
290
344
  if (!hasEmit && !hasOn)
291
345
  continue;
292
346
  const nodesInFile = ctx.getNodesInFile(file);
293
- const lineOf = (idx) => content.slice(0, idx).split('\n').length;
347
+ const lineOf = makeLineAt(content, 1);
294
348
  if (hasEmit) {
295
349
  EMIT_RE.lastIndex = 0;
296
350
  let m;
@@ -353,10 +407,13 @@ async function eventEmitterEdges(ctx, onYield) {
353
407
  * `this.setState`). Over-approximation (all setState methods reach render) is
354
408
  * accepted — it's reachability-correct, like the callback channels.
355
409
  */
356
- function reactRenderEdges(queries, ctx) {
410
+ async function reactRenderEdges(queries, ctx, onYield) {
411
+ let scanned255 = 0;
357
412
  const edges = [];
358
413
  const seen = new Set();
359
- for (const cls of queries.getNodesByKind('class')) {
414
+ for (const cls of queries.iterateNodesByKind('class')) {
415
+ if ((++scanned255 & 63) === 0)
416
+ await onYield();
360
417
  const children = queries.getOutgoingEdges(cls.id, ['contains'])
361
418
  .map((e) => queries.getNodeById(e.target))
362
419
  .filter((n) => !!n && n.kind === 'method');
@@ -396,10 +453,13 @@ function reactRenderEdges(queries, ctx) {
396
453
  * body calls `setState(` → `build`. The setState gate + `.dart` file keep this to
397
454
  * Flutter State classes. Over-approximation accepted (reachability-correct).
398
455
  */
399
- function flutterBuildEdges(queries, ctx) {
456
+ async function flutterBuildEdges(queries, ctx, onYield) {
457
+ let scanned255 = 0;
400
458
  const edges = [];
401
459
  const seen = new Set();
402
- for (const cls of queries.getNodesByKind('class')) {
460
+ for (const cls of queries.iterateNodesByKind('class')) {
461
+ if ((++scanned255 & 63) === 0)
462
+ await onYield();
403
463
  const children = queries.getOutgoingEdges(cls.id, ['contains'])
404
464
  .map((e) => queries.getNodeById(e.target))
405
465
  .filter((n) => !!n && n.kind === 'method');
@@ -458,10 +518,13 @@ const ARKUI_ARRAY_MUTATORS = 'push|pop|shift|unshift|splice|sort|reverse|fill';
458
518
  * with no reactive properties, gets nothing (this is the precision line the
459
519
  * all-sibling-methods design would erase).
460
520
  */
461
- function arkuiStateBuildEdges(queries, ctx) {
521
+ async function arkuiStateBuildEdges(queries, ctx, onYield) {
522
+ let scanned255 = 0;
462
523
  const edges = [];
463
524
  const seen = new Set();
464
- for (const struct of queries.getNodesByKind('struct')) {
525
+ for (const struct of queries.iterateNodesByKind('struct')) {
526
+ if ((++scanned255 & 63) === 0)
527
+ await onYield();
465
528
  if (struct.language !== 'arkts')
466
529
  continue;
467
530
  const children = queries.getOutgoingEdges(struct.id, ['contains'])
@@ -526,7 +589,8 @@ const ARKUI_EMITTER_FANOUT_CAP = 8;
526
589
  * handling — their bodies' calls already attribute to the registering method,
527
590
  * so targeting that method keeps the chain connected.
528
591
  */
529
- function arkuiEmitterEdges(ctx) {
592
+ async function arkuiEmitterEdges(ctx, onYield) {
593
+ let scannedFiles = 0;
530
594
  // bucket key -> emit sites / handler sites
531
595
  const emits = new Map();
532
596
  const handlers = new Map();
@@ -542,6 +606,8 @@ function arkuiEmitterEdges(ctx) {
542
606
  return '';
543
607
  };
544
608
  for (const file of ctx.getAllFiles()) {
609
+ if ((++scannedFiles & 15) === 0)
610
+ await onYield();
545
611
  if (!file.endsWith('.ets'))
546
612
  continue;
547
613
  const content = ctx.readFile(file);
@@ -634,7 +700,7 @@ const ARKUI_ROUTER_RE = /\brouter\s*\.\s*(?:pushUrl|replaceUrl)\s*\(\s*\{[^)]{0,
634
700
  * anything still ambiguous is dropped rather than guessed. Only `@Entry`
635
701
  * structs qualify as targets — the decorator is what makes a file a page.
636
702
  */
637
- function arkuiRouterEdges(ctx) {
703
+ async function arkuiRouterEdges(ctx, onYield) {
638
704
  const edges = [];
639
705
  const seen = new Set();
640
706
  const allFiles = ctx.getAllFiles();
@@ -649,7 +715,10 @@ function arkuiRouterEdges(ctx) {
649
715
  }
650
716
  return '';
651
717
  };
718
+ let scannedFiles = 0;
652
719
  for (const file of allFiles) {
720
+ if ((++scannedFiles & 15) === 0)
721
+ await onYield();
653
722
  if (!file.endsWith('.ets'))
654
723
  continue;
655
724
  const content = ctx.readFile(file);
@@ -704,14 +773,17 @@ function arkuiRouterEdges(ctx) {
704
773
  * implementation(s). Over-approximation accepted (reachability-correct); capped
705
774
  * per class and gated to C++ to avoid touching other languages' dispatch.
706
775
  */
707
- function cppOverrideEdges(queries) {
776
+ async function cppOverrideEdges(queries, onYield) {
777
+ let scanned255 = 0;
708
778
  const edges = [];
709
779
  const seen = new Set();
710
780
  const methodsOf = (classId) => queries
711
781
  .getOutgoingEdges(classId, ['contains'])
712
782
  .map((e) => queries.getNodeById(e.target))
713
783
  .filter((n) => !!n && n.kind === 'method');
714
- for (const cls of queries.getNodesByKind('class')) {
784
+ for (const cls of queries.iterateNodesByKind('class')) {
785
+ if ((++scanned255 & 63) === 0)
786
+ await onYield();
715
787
  const subMethods = methodsOf(cls.id).filter((n) => n.language === 'cpp');
716
788
  if (subMethods.length === 0)
717
789
  continue;
@@ -779,7 +851,8 @@ const IFACE_OVERRIDE_LANGS = new Set([
779
851
  * with the other dispatch synthesizers; capped per interface. Empty interfaces
780
852
  * (`any`) are skipped so they don't match every struct.
781
853
  */
782
- function goImplementsEdges(queries) {
854
+ async function goImplementsEdges(queries, onYield) {
855
+ let scanned255 = 0;
783
856
  const edges = [];
784
857
  const seen = new Set();
785
858
  const methodNameSet = (id) => new Set(queries
@@ -787,11 +860,24 @@ function goImplementsEdges(queries) {
787
860
  .map((e) => queries.getNodeById(e.target))
788
861
  .filter((n) => !!n && n.kind === 'method')
789
862
  .map((n) => n.name));
790
- const goStructs = queries.getNodesByKind('struct').filter((s) => s.language === 'go');
863
+ // Materializes GO structs only (the pass is language-gated by the caller),
864
+ // never the whole struct kind — that array is O(nodes) on struct-heavy
865
+ // repos like the Linux kernel (#1212).
866
+ const goStructs = [];
867
+ for (const s of queries.iterateNodesByKind('struct')) {
868
+ if ((++scanned255 & 63) === 0)
869
+ await onYield();
870
+ if (s.language === 'go')
871
+ goStructs.push(s);
872
+ }
791
873
  const structMethods = new Map();
792
874
  for (const s of goStructs)
793
875
  structMethods.set(s.id, methodNameSet(s.id));
794
- for (const iface of queries.getNodesByKind('interface')) {
876
+ for (const iface of queries.iterateNodesByKind('interface')) {
877
+ if ((++scanned255 & 63) === 0)
878
+ await onYield();
879
+ if ((++scanned255 & 63) === 0)
880
+ await onYield();
795
881
  if (iface.language !== 'go')
796
882
  continue;
797
883
  const want = methodNameSet(iface.id);
@@ -851,7 +937,8 @@ function goImplementsEdges(queries) {
851
937
  * matching the same-file edges extraction already emits). Skips methods that
852
938
  * already have a type parent (the same-file case). (#583, cross-file half)
853
939
  */
854
- function goCrossFileMethodContainsEdges(queries) {
940
+ async function goCrossFileMethodContainsEdges(queries, onYield) {
941
+ let scanned255 = 0;
855
942
  const edges = [];
856
943
  const seen = new Set();
857
944
  const TYPE_KINDS = new Set(['struct', 'class', 'interface', 'enum', 'type_alias']);
@@ -859,7 +946,11 @@ function goCrossFileMethodContainsEdges(queries) {
859
946
  const i = p.replace(/\\/g, '/').lastIndexOf('/');
860
947
  return i >= 0 ? p.slice(0, i) : '';
861
948
  };
862
- for (const method of queries.getNodesByKind('method')) {
949
+ for (const method of queries.iterateNodesByKind('method')) {
950
+ if ((++scanned255 & 63) === 0)
951
+ await onYield();
952
+ if ((++scanned255 & 63) === 0)
953
+ await onYield();
863
954
  if (method.language !== 'go')
864
955
  continue;
865
956
  // The receiver type is encoded in the method's qualifiedName as `Recv::name`
@@ -929,13 +1020,20 @@ const KMP_TYPE_KINDS = new Set(['class', 'interface', 'struct', 'enum', 'type_al
929
1020
  function kmpKindsCompatible(a, b) {
930
1021
  return a === b || (KMP_TYPE_KINDS.has(a) && KMP_TYPE_KINDS.has(b));
931
1022
  }
932
- function kotlinExpectActualEdges(queries) {
1023
+ async function kotlinExpectActualEdges(queries, onYield) {
1024
+ let scanned255 = 0;
933
1025
  const edges = [];
934
1026
  const seen = new Set();
935
- const actuals = queries
936
- .getAllNodes()
937
- .filter((n) => n.language === 'kotlin' && !!n.decorators?.includes('actual'));
938
- for (const act of actuals) {
1027
+ // SQL-side language+decorator pre-filter, streamed. The old
1028
+ // `getAllNodes().filter(...)` hydrated the ENTIRE node table into one array
1029
+ // just to find kotlin `actual` declarations — on a 2M-node graph that alone
1030
+ // exceeded Node's default heap and killed the index (#1212). The LIKE
1031
+ // pre-filter can over-match (substring), so the exact decorator check stays.
1032
+ for (const act of queries.iterateNodesByLanguageWithDecorator('kotlin', 'actual')) {
1033
+ if ((++scanned255 & 63) === 0)
1034
+ await onYield();
1035
+ if (!act.decorators?.includes('actual'))
1036
+ continue;
939
1037
  let added = 0;
940
1038
  for (const cand of queries.getNodesByQualifiedNameExact(act.qualifiedName)) {
941
1039
  if (added >= MAX_CALLBACKS_PER_CHANNEL)
@@ -969,7 +1067,8 @@ function kotlinExpectActualEdges(queries) {
969
1067
  }
970
1068
  return edges;
971
1069
  }
972
- function interfaceOverrideEdges(queries) {
1070
+ async function interfaceOverrideEdges(queries, onYield) {
1071
+ let scanned255 = 0;
973
1072
  const edges = [];
974
1073
  const seen = new Set();
975
1074
  const methodsOf = (classId) => queries
@@ -981,7 +1080,9 @@ function interfaceOverrideEdges(queries) {
981
1080
  // types that conform to protocols. Iterate both.
982
1081
  const concreteKinds = ['class', 'struct'];
983
1082
  for (const kind of concreteKinds) {
984
- for (const cls of queries.getNodesByKind(kind)) {
1083
+ for (const cls of queries.iterateNodesByKind(kind)) {
1084
+ if ((++scanned255 & 63) === 0)
1085
+ await onYield();
985
1086
  const implMethods = methodsOf(cls.id).filter((n) => IFACE_OVERRIDE_LANGS.has(n.language));
986
1087
  if (implMethods.length === 0)
987
1088
  continue;
@@ -1055,7 +1156,8 @@ function interfaceOverrideEdges(queries) {
1055
1156
  * Provenance: `heuristic`, `synthesizedBy: 'go-grpc-stub-impl'`. The
1056
1157
  * stub's source line is the wiring site shown in the trace trail.
1057
1158
  */
1058
- function goGrpcStubImplEdges(queries) {
1159
+ async function goGrpcStubImplEdges(queries, onYield) {
1160
+ let scanned255 = 0;
1059
1161
  const edges = [];
1060
1162
  const seen = new Set();
1061
1163
  const STUB_RE = /^Unimplemented.*Server$/;
@@ -1067,7 +1169,9 @@ function goGrpcStubImplEdges(queries) {
1067
1169
  const methodNamesByStruct = new Map();
1068
1170
  const methodNodesByStruct = new Map();
1069
1171
  const goStructs = [];
1070
- for (const s of queries.getNodesByKind('struct')) {
1172
+ for (const s of queries.iterateNodesByKind('struct')) {
1173
+ if ((++scanned255 & 63) === 0)
1174
+ await onYield();
1071
1175
  if (s.language !== 'go')
1072
1176
  continue;
1073
1177
  goStructs.push(s);
@@ -1151,11 +1255,14 @@ function goGrpcStubImplEdges(queries) {
1151
1255
  * (or nothing) and are dropped.
1152
1256
  */
1153
1257
  async function reactJsxChildEdges(ctx, onYield) {
1258
+ let scannedFiles = 0;
1154
1259
  const edges = [];
1155
1260
  const seen = new Set();
1156
1261
  const PARENT_KINDS = new Set(['method', 'function', 'component']);
1157
1262
  let scanned = 0;
1158
1263
  for (const file of ctx.getAllFiles()) {
1264
+ if ((++scannedFiles & 15) === 0)
1265
+ await onYield();
1159
1266
  if ((++scanned & 255) === 0)
1160
1267
  await onYield(); // #1091: yield mid-scan on huge graphs
1161
1268
  const content = ctx.readFile(file);
@@ -1205,7 +1312,9 @@ async function reactJsxChildEdges(ctx, onYield) {
1205
1312
  * component, handler→function/method) keeps precision; inline arrows / `$emit`
1206
1313
  * skipped.
1207
1314
  */
1208
- function vueTemplateEdges(ctx) {
1315
+ async function vueTemplateEdges(ctx, onYield) {
1316
+ let scannedFiles = 0;
1317
+ let scanned255 = 0;
1209
1318
  const edges = [];
1210
1319
  const seen = new Set();
1211
1320
  const COMPONENT_KINDS = new Set(['component', 'function', 'class']);
@@ -1219,12 +1328,16 @@ function vueTemplateEdges(ctx) {
1219
1328
  // misses it (flat components match by basename and don't need this). Map each
1220
1329
  // nested component's Nuxt name → node so those template usages resolve.
1221
1330
  const nuxtComponents = new Map();
1222
- for (const c of ctx.getNodesByKind('component')) {
1331
+ for (const c of (ctx.iterateNodesByKind?.('component') ?? ctx.getNodesByKind('component'))) {
1332
+ if ((++scanned255 & 63) === 0)
1333
+ await onYield();
1223
1334
  const nn = nuxtComponentName(c.filePath);
1224
1335
  if (nn && !nuxtComponents.has(nn))
1225
1336
  nuxtComponents.set(nn, c);
1226
1337
  }
1227
1338
  for (const file of ctx.getAllFiles()) {
1339
+ if ((++scannedFiles & 15) === 0)
1340
+ await onYield();
1228
1341
  if (!file.endsWith('.vue'))
1229
1342
  continue;
1230
1343
  const content = ctx.readFile(file);
@@ -1358,18 +1471,21 @@ const RN_JVM_EMIT_RE = /\.emit\s*\(\s*"([^"]+)"\s*,/g;
1358
1471
  // statement and stops at a block boundary, so the wrapper DEFINITION (whose `(`
1359
1472
  // is followed by `… ) {`) never matches. Multi-line tolerant. (java/kotlin/swift)
1360
1473
  const RN_NATIVE_SENDEVENT_RE = /\bsendEvent\s*\([^;{}]*?"([^"]+)"/g;
1361
- function rnEventEdges(ctx) {
1474
+ async function rnEventEdges(ctx, onYield) {
1475
+ let scannedFiles = 0;
1362
1476
  // Native dispatchers (source = the native method whose body sends the
1363
1477
  // event) and JS handlers (target = the function/method registered as
1364
1478
  // the listener) keyed by event name.
1365
1479
  const nativeDispatchersByEvent = new Map();
1366
1480
  const jsHandlersByEvent = new Map();
1367
1481
  for (const file of ctx.getAllFiles()) {
1482
+ if ((++scannedFiles & 15) === 0)
1483
+ await onYield();
1368
1484
  const content = ctx.readFile(file);
1369
1485
  if (!content)
1370
1486
  continue;
1371
1487
  const nodesInFile = ctx.getNodesInFile(file);
1372
- const lineOf = (idx) => content.slice(0, idx).split('\n').length;
1488
+ const lineOf = makeLineAt(content, 1);
1373
1489
  const addDispatcher = (event, line) => {
1374
1490
  const disp = enclosingFn(nodesInFile, line);
1375
1491
  if (!disp)
@@ -1552,11 +1668,14 @@ const FABRIC_NATIVE_SUFFIXES = ['', 'View', 'ViewManager', 'ComponentView', 'Man
1552
1668
  * caller. The Expo method nodes are id-prefixed `expo-module:` and qualified
1553
1669
  * `<file>::<module>.<method>` by the framework extractor.
1554
1670
  */
1555
- function expoCrossPlatformEdges(queries) {
1671
+ async function expoCrossPlatformEdges(queries, onYield) {
1672
+ let scanned255 = 0;
1556
1673
  const edges = [];
1557
1674
  const seen = new Set();
1558
1675
  const byKey = new Map();
1559
- for (const m of queries.getNodesByKind('method')) {
1676
+ for (const m of queries.iterateNodesByKind('method')) {
1677
+ if ((++scanned255 & 63) === 0)
1678
+ await onYield();
1560
1679
  if (!m.id.startsWith('expo-module:'))
1561
1680
  continue;
1562
1681
  const key = m.qualifiedName.split('::').pop(); // `<module>.<method>`
@@ -1605,7 +1724,8 @@ function expoCrossPlatformEdges(queries) {
1605
1724
  * `getFreeDiskStorage`) — that's the JS-visible name, and how the iOS selector
1606
1725
  * lines up with the bare Android method name.
1607
1726
  */
1608
- function rnCrossPlatformEdges(queries) {
1727
+ async function rnCrossPlatformEdges(queries, onYield) {
1728
+ let scanned255 = 0;
1609
1729
  const edges = [];
1610
1730
  const seen = new Set();
1611
1731
  const NATIVE = new Set(['java', 'kotlin', 'objc', 'cpp']);
@@ -1627,6 +1747,8 @@ function rnCrossPlatformEdges(queries) {
1627
1747
  // below only runs for genuine cross-platform candidates.
1628
1748
  const byName = new Map();
1629
1749
  for (const m of queries.iterateNodesByKind('method')) {
1750
+ if ((++scanned255 & 63) === 0)
1751
+ await onYield();
1630
1752
  if (!NATIVE.has(m.language))
1631
1753
  continue;
1632
1754
  const key = norm(m.name);
@@ -1677,17 +1799,27 @@ function rnCrossPlatformEdges(queries) {
1677
1799
  }
1678
1800
  return edges;
1679
1801
  }
1680
- function fabricNativeImplEdges(ctx) {
1802
+ async function fabricNativeImplEdges(ctx, onYield) {
1803
+ let scanned255 = 0;
1681
1804
  const edges = [];
1682
1805
  const seen = new Set();
1683
1806
  // The Fabric extractor IDs are prefixed `fabric-component:` so we can
1684
- // filter to just those without iterating all `component` nodes.
1685
- const components = ctx.getNodesByKind('component').filter((n) => n.id.startsWith('fabric-component:'));
1807
+ // filter to just those while streaming — never materializing the whole
1808
+ // `component` kind (#1212).
1809
+ const components = [];
1810
+ for (const n of (ctx.iterateNodesByKind?.('component') ?? ctx.getNodesByKind('component'))) {
1811
+ if ((++scanned255 & 63) === 0)
1812
+ await onYield();
1813
+ if (n.id.startsWith('fabric-component:'))
1814
+ components.push(n);
1815
+ }
1686
1816
  if (components.length === 0)
1687
1817
  return edges;
1688
1818
  // Pre-index native classes by name for O(1) lookup.
1689
1819
  const nativeClassesByName = new Map();
1690
- for (const n of ctx.getNodesByKind('class')) {
1820
+ for (const n of (ctx.iterateNodesByKind?.('class') ?? ctx.getNodesByKind('class'))) {
1821
+ if ((++scanned255 & 63) === 0)
1822
+ await onYield();
1691
1823
  if (n.language !== 'objc' && n.language !== 'kotlin' && n.language !== 'java' && n.language !== 'cpp')
1692
1824
  continue;
1693
1825
  const arr = nativeClassesByName.get(n.name);
@@ -1740,12 +1872,15 @@ function fabricNativeImplEdges(ctx) {
1740
1872
  * same simple name) are dropped. We need-not bridge by package because Java
1741
1873
  * mapper interfaces are typically uniquely named within a project.
1742
1874
  */
1743
- function mybatisJavaXmlEdges(queries) {
1875
+ async function mybatisJavaXmlEdges(queries, onYield) {
1876
+ let scanned255 = 0;
1744
1877
  const edges = [];
1745
1878
  const seen = new Set();
1746
1879
  // Index Java methods by `<ClassName>::<methodName>` for O(1) lookup.
1747
1880
  const javaIndex = new Map();
1748
1881
  for (const m of queries.iterateNodesByKind('method')) {
1882
+ if ((++scanned255 & 63) === 0)
1883
+ await onYield();
1749
1884
  if (m.language !== 'java' && m.language !== 'kotlin')
1750
1885
  continue;
1751
1886
  const parts = m.qualifiedName.split('::');
@@ -1761,6 +1896,8 @@ function mybatisJavaXmlEdges(queries) {
1761
1896
  javaIndex.set(key, [m]);
1762
1897
  }
1763
1898
  for (const xml of queries.iterateNodesByKind('method')) {
1899
+ if ((++scanned255 & 63) === 0)
1900
+ await onYield();
1764
1901
  if (xml.language !== 'xml')
1765
1902
  continue;
1766
1903
  // Qualified name: `<namespace>::<id>`. Extract the simple class name.
@@ -1874,10 +2011,14 @@ function goHandlerIdent(expr) {
1874
2011
  const m = cleaned.match(/(?:\.|^)([A-Za-z_]\w*)$/);
1875
2012
  return m ? m[1] : null;
1876
2013
  }
1877
- function ginMiddlewareChainEdges(queries, ctx) {
2014
+ async function ginMiddlewareChainEdges(queries, ctx, onYield) {
2015
+ let scanned255 = 0;
2016
+ let scannedFiles = 0;
1878
2017
  // 1. Find the chain dispatcher(s): a Go method that invokes a `handlers` slice by index.
1879
2018
  const dispatchers = [];
1880
2019
  for (const n of queries.iterateNodesByKind('method')) {
2020
+ if ((++scanned255 & 63) === 0)
2021
+ await onYield();
1881
2022
  if (n.language !== 'go')
1882
2023
  continue;
1883
2024
  const content = ctx.readFile(n.filePath);
@@ -1892,6 +2033,8 @@ function ginMiddlewareChainEdges(queries, ctx) {
1892
2033
  // closures are dropped by goHandlerIdent; the rest are HandlerFuncs.
1893
2034
  const registered = new Map(); // name → registeredAt (file:line)
1894
2035
  for (const file of ctx.getAllFiles()) {
2036
+ if ((++scannedFiles & 15) === 0)
2037
+ await onYield();
1895
2038
  if (!file.endsWith('.go'))
1896
2039
  continue;
1897
2040
  const content = ctx.readFile(file);
@@ -1947,10 +2090,13 @@ function ginMiddlewareChainEdges(queries, ctx) {
1947
2090
  * clause. Link the unit → its form so a `.dfm`/`.fmx` used only as a form
1948
2091
  * definition isn't orphaned, and editing the form surfaces its code-behind unit.
1949
2092
  */
1950
- function pascalFormEdges(ctx) {
2093
+ async function pascalFormEdges(ctx, onYield) {
2094
+ let scannedFiles = 0;
1951
2095
  const edges = [];
1952
2096
  const allFiles = new Set(ctx.getAllFiles());
1953
2097
  for (const file of allFiles) {
2098
+ if ((++scannedFiles & 255) === 0)
2099
+ await onYield();
1954
2100
  if (!/\.(dfm|fmx)$/i.test(file))
1955
2101
  continue;
1956
2102
  const pasFile = file.replace(/\.(dfm|fmx)$/i, '.pas');
@@ -1986,12 +2132,15 @@ function pascalFormEdges(ctx) {
1986
2132
  * a loader's data shows the page it feeds) and the page's dependencies include
1987
2133
  * its loader.
1988
2134
  */
1989
- function svelteKitLoadEdges(ctx) {
2135
+ async function svelteKitLoadEdges(ctx, onYield) {
2136
+ let scannedFiles = 0;
1990
2137
  const edges = [];
1991
2138
  const allFiles = new Set(ctx.getAllFiles());
1992
2139
  const HOOKS = new Set(['load', 'actions']);
1993
2140
  const HOOK_KINDS = new Set(['function', 'method', 'constant', 'variable']);
1994
2141
  for (const file of allFiles) {
2142
+ if ((++scannedFiles & 255) === 0)
2143
+ await onYield();
1995
2144
  const m = file.match(/(.*\/)(\+(?:page|layout))\.svelte$/);
1996
2145
  if (!m)
1997
2146
  continue;
@@ -2040,10 +2189,13 @@ function svelteKitLoadEdges(ctx) {
2040
2189
  const THUNK_DECL_RE = /create(?:Async)?Thunk/;
2041
2190
  const THUNK_DISPATCH_RE = /\bdispatch\s*\(\s*([A-Za-z_]\w*)\s*[(),]/g;
2042
2191
  const THUNK_FANOUT_CAP = 24;
2043
- function reduxThunkEdges(queries, ctx) {
2192
+ async function reduxThunkEdges(queries, ctx, onYield) {
2193
+ let scanned255 = 0;
2044
2194
  const edges = [];
2045
2195
  const seen = new Set();
2046
2196
  for (const node of queries.iterateNodesByKind('constant')) {
2197
+ if ((++scanned255 & 63) === 0)
2198
+ await onYield();
2047
2199
  // Cheap gate: the initializer (captured in `signature`) must be a create(Async)Thunk call —
2048
2200
  // avoids reading every constant's body on a large repo.
2049
2201
  if (!node.signature || !THUNK_DECL_RE.test(node.signature))
@@ -2175,10 +2327,13 @@ function resolveRegistryHandler(ctx, name, chained) {
2175
2327
  return cands.find((n) => n.kind === 'method') ?? null;
2176
2328
  }
2177
2329
  async function objectRegistryEdges(ctx, onYield) {
2330
+ let scannedFiles = 0;
2178
2331
  const edges = [];
2179
2332
  const seen = new Set();
2180
2333
  let scanned = 0;
2181
2334
  for (const file of ctx.getAllFiles()) {
2335
+ if ((++scannedFiles & 15) === 0)
2336
+ await onYield();
2182
2337
  if ((++scanned & 255) === 0)
2183
2338
  await onYield(); // #1091: yield mid-scan on huge graphs
2184
2339
  if (!REGISTRY_JS_EXT.test(file))
@@ -2290,10 +2445,13 @@ function rtkEndpointNameFromHook(hook) {
2290
2445
  return null;
2291
2446
  return mid.charAt(0).toLowerCase() + mid.slice(1);
2292
2447
  }
2293
- function rtkQueryEdges(queries, ctx) {
2448
+ async function rtkQueryEdges(queries, ctx, onYield) {
2449
+ let scanned255 = 0;
2294
2450
  const edges = [];
2295
2451
  const seen = new Set();
2296
2452
  for (const hook of queries.iterateNodesByKind('function')) {
2453
+ if ((++scanned255 & 63) === 0)
2454
+ await onYield();
2297
2455
  // Only our extracted generated-hook bindings (sentinel) — not a real hook fn.
2298
2456
  if (hook.signature !== RTK_GENERATED_HOOK_SIGNATURE)
2299
2457
  continue;
@@ -2337,10 +2495,13 @@ const PINIA_FACTORY_RE = /\b(?:export\s+)?const\s+(\w+)\s*=\s*defineStore\s*\(/g
2337
2495
  const PINIA_BIND_RE = /\bconst\s+(\w+)\s*=\s*(?:await\s+)?(\w+)\s*\(/g;
2338
2496
  const PINIA_CALL_RE = /(\w+)\s*\.\s*(\w+)\s*\(/g;
2339
2497
  const PINIA_FANOUT_CAP = 80;
2340
- function piniaStoreEdges(ctx) {
2498
+ async function piniaStoreEdges(ctx, onYield) {
2499
+ let scannedFiles = 0;
2341
2500
  // 1. Map each `const useXStore = defineStore(...)` factory → its store file.
2342
2501
  const factoryFile = new Map();
2343
2502
  for (const file of ctx.getAllFiles()) {
2503
+ if ((++scannedFiles & 15) === 0)
2504
+ await onYield();
2344
2505
  if (!PINIA_CONSUMER_EXT.test(file))
2345
2506
  continue;
2346
2507
  const content = ctx.readFile(file);
@@ -2356,6 +2517,8 @@ function piniaStoreEdges(ctx) {
2356
2517
  const edges = [];
2357
2518
  const seen = new Set();
2358
2519
  for (const file of ctx.getAllFiles()) {
2520
+ if ((++scannedFiles & 15) === 0)
2521
+ await onYield();
2359
2522
  if (!PINIA_CONSUMER_EXT.test(file))
2360
2523
  continue;
2361
2524
  const content = ctx.readFile(file);
@@ -2428,7 +2591,8 @@ const VUEX_FANOUT_CAP = 120;
2428
2591
  function pathHasSegment(filePath, seg) {
2429
2592
  return new RegExp('[\\\\/]' + seg.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '[\\\\/.]').test(filePath);
2430
2593
  }
2431
- function vuexDispatchEdges(ctx) {
2594
+ async function vuexDispatchEdges(ctx, onYield) {
2595
+ let scannedFiles = 0;
2432
2596
  const storeFileCache = new Map();
2433
2597
  const isStoreFile = (file) => {
2434
2598
  let v = storeFileCache.get(file);
@@ -2466,6 +2630,8 @@ function vuexDispatchEdges(ctx) {
2466
2630
  const edges = [];
2467
2631
  const seen = new Set();
2468
2632
  for (const file of ctx.getAllFiles()) {
2633
+ if ((++scannedFiles & 15) === 0)
2634
+ await onYield();
2469
2635
  if (!PINIA_CONSUMER_EXT.test(file))
2470
2636
  continue;
2471
2637
  const content = ctx.readFile(file);
@@ -2525,7 +2691,8 @@ const CELERY_TASK_DECORATOR_RE = /@\s*(?:[A-Za-z_][\w.]*\.)?(?:shared_task|task)
2525
2691
  const CELERY_PY_EXT = /\.py$/;
2526
2692
  const CELERY_FANOUT_CAP = 80;
2527
2693
  const CELERY_DECORATOR_LOOKBACK = 12; // max lines above a `def` to scan for its decorators
2528
- function celeryDispatchEdges(ctx) {
2694
+ async function celeryDispatchEdges(ctx, onYield) {
2695
+ let scannedFiles = 0;
2529
2696
  // Memoize the decorator check per task-candidate node: it reads the file and scans a few
2530
2697
  // lines above the def. Only called on names that are actually `.delay`/`.apply_async`
2531
2698
  // receivers, so the candidate set stays small.
@@ -2569,6 +2736,8 @@ function celeryDispatchEdges(ctx) {
2569
2736
  const edges = [];
2570
2737
  const seen = new Set();
2571
2738
  for (const file of ctx.getAllFiles()) {
2739
+ if ((++scannedFiles & 15) === 0)
2740
+ await onYield();
2572
2741
  if (!CELERY_PY_EXT.test(file))
2573
2742
  continue;
2574
2743
  const content = ctx.readFile(file);
@@ -2647,15 +2816,24 @@ function springFirstParamType(sig) {
2647
2816
  const type = toks[toks.length - 2].replace(/<.*$/, ''); // drop generic args
2648
2817
  return /^[A-Z][A-Za-z0-9_]*$/.test(type) ? type : null;
2649
2818
  }
2650
- function springEventEdges(ctx) {
2819
+ async function springEventEdges(ctx, onYield) {
2820
+ let scannedFiles = 0;
2651
2821
  // Pass 1 — event-type → listener methods, scanning only event-relevant files.
2822
+ // This is the ONLY full read sweep: publisher files are recorded here so
2823
+ // pass 2 re-reads just those instead of every .java file again (#1212 —
2824
+ // the double full-repo read was one of the tail's longest unyielded spans).
2652
2825
  const listeners = new Map();
2826
+ const publisherFiles = [];
2653
2827
  for (const file of ctx.getAllFiles()) {
2828
+ if ((++scannedFiles & 15) === 0)
2829
+ await onYield();
2654
2830
  if (!SPRING_JAVA_EXT.test(file))
2655
2831
  continue;
2656
2832
  const content = ctx.readFile(file);
2657
2833
  if (!content)
2658
2834
  continue;
2835
+ if (content.includes('.publishEvent('))
2836
+ publisherFiles.push(file);
2659
2837
  const hasAnno = content.includes('@EventListener') || content.includes('@TransactionalEventListener');
2660
2838
  const hasAppListener = SPRING_APP_LISTENER_RE.test(content);
2661
2839
  if (!hasAnno && !hasAppListener)
@@ -2695,12 +2873,13 @@ function springEventEdges(ctx) {
2695
2873
  }
2696
2874
  if (!listeners.size)
2697
2875
  return [];
2698
- // Pass 2 — link each publishEvent(new XEvent(...)) site → every listener of XEvent.
2876
+ // Pass 2 — link each publishEvent(new XEvent(...)) site → every listener of
2877
+ // XEvent. Only the publisher files recorded in pass 1 are (re-)read.
2699
2878
  const edges = [];
2700
2879
  const seen = new Set();
2701
- for (const file of ctx.getAllFiles()) {
2702
- if (!SPRING_JAVA_EXT.test(file))
2703
- continue;
2880
+ for (const file of publisherFiles) {
2881
+ if ((++scannedFiles & 15) === 0)
2882
+ await onYield();
2704
2883
  const content = ctx.readFile(file);
2705
2884
  if (!content || !content.includes('.publishEvent('))
2706
2885
  continue;
@@ -2785,10 +2964,13 @@ function resolveMediatrArgType(arg, lines, methodStart, dispatchLine) {
2785
2964
  }
2786
2965
  return declType;
2787
2966
  }
2788
- function mediatrDispatchEdges(ctx) {
2967
+ async function mediatrDispatchEdges(ctx, onYield) {
2968
+ let scannedFiles = 0;
2789
2969
  // Pass 1 — request/notification type → the Handle method of each handler class.
2790
2970
  const handlers = new Map();
2791
2971
  for (const file of ctx.getAllFiles()) {
2972
+ if ((++scannedFiles & 15) === 0)
2973
+ await onYield();
2792
2974
  if (!MEDIATR_CS_EXT.test(file))
2793
2975
  continue;
2794
2976
  const content = ctx.readFile(file);
@@ -2822,6 +3004,8 @@ function mediatrDispatchEdges(ctx) {
2822
3004
  const edges = [];
2823
3005
  const seen = new Set();
2824
3006
  for (const file of ctx.getAllFiles()) {
3007
+ if ((++scannedFiles & 15) === 0)
3008
+ await onYield();
2825
3009
  if (!MEDIATR_CS_EXT.test(file))
2826
3010
  continue;
2827
3011
  const content = ctx.readFile(file);
@@ -2885,7 +3069,8 @@ const SIDEKIQ_DISPATCH_RE = /([A-Z][A-Za-z0-9_]*(?:::[A-Z][A-Za-z0-9_]*)*)\s*\.\
2885
3069
  const SIDEKIQ_WORKER_RE = /\binclude\s+Sidekiq::(?:Job|Worker)\b/;
2886
3070
  const SIDEKIQ_RB_EXT = /\.rb$/;
2887
3071
  const SIDEKIQ_FANOUT_CAP = 80;
2888
- function sidekiqDispatchEdges(ctx) {
3072
+ async function sidekiqDispatchEdges(ctx, onYield) {
3073
+ let scannedFiles = 0;
2889
3074
  // class node id → its instance `perform` method (null if the class isn't a Sidekiq worker),
2890
3075
  // memoized. Reads the class body for the mixin; only consulted for actual dispatch receivers.
2891
3076
  const performCache = new Map();
@@ -2922,6 +3107,8 @@ function sidekiqDispatchEdges(ctx) {
2922
3107
  const edges = [];
2923
3108
  const seen = new Set();
2924
3109
  for (const file of ctx.getAllFiles()) {
3110
+ if ((++scannedFiles & 15) === 0)
3111
+ await onYield();
2925
3112
  if (!SIDEKIQ_RB_EXT.test(file))
2926
3113
  continue;
2927
3114
  const content = ctx.readFile(file);
@@ -3105,12 +3292,15 @@ function nixLeadingPlainSegments(name) {
3105
3292
  return segs;
3106
3293
  }
3107
3294
  async function nixOptionPathEdges(queries, onYield) {
3295
+ let scanned255 = 0;
3108
3296
  // One streaming pass over nix bindings (variables + the odd function-valued
3109
3297
  // option); memory stays O(bindings-kept), not O(all nodes) (#610).
3110
3298
  const byFile = new Map();
3111
3299
  let scanned = 0;
3112
3300
  for (const kind of ['variable', 'function']) {
3113
3301
  for (const node of queries.iterateNodesByKind(kind)) {
3302
+ if ((++scanned255 & 63) === 0)
3303
+ await onYield();
3114
3304
  if ((++scanned & 0x3fff) === 0 && onYield)
3115
3305
  await onYield();
3116
3306
  if (node.language !== 'nix')
@@ -3223,9 +3413,18 @@ async function nixOptionPathEdges(queries, onYield) {
3223
3413
  }
3224
3414
  return edges;
3225
3415
  }
3226
- function erlangBehaviourDispatchEdges(queries, ctx) {
3227
- // Cheap language gate: no Erlang modules → no cost beyond one kind query.
3228
- const erlangModules = queries.getNodesByKind('namespace').filter((n) => n.language === 'erlang');
3416
+ async function erlangBehaviourDispatchEdges(queries, ctx, onYield) {
3417
+ let scannedFiles = 0;
3418
+ let scanned255 = 0;
3419
+ // Cheap language gate: no Erlang modules → no cost beyond one streamed
3420
+ // kind scan (never a materialized array of every namespace — #1212).
3421
+ const erlangModules = [];
3422
+ for (const n of queries.iterateNodesByKind('namespace')) {
3423
+ if ((++scanned255 & 63) === 0)
3424
+ await onYield();
3425
+ if (n.language === 'erlang')
3426
+ erlangModules.push(n);
3427
+ }
3229
3428
  if (erlangModules.length === 0)
3230
3429
  return [];
3231
3430
  // Pass 1 — scan every Erlang file with `-callback` decls: behaviour module →
@@ -3239,6 +3438,8 @@ function erlangBehaviourDispatchEdges(queries, ctx) {
3239
3438
  const declaringBehaviours = new Map(); // `fn/arity` → behaviour namespaces
3240
3439
  const callbackNames = new Set();
3241
3440
  for (const file of ctx.getAllFiles()) {
3441
+ if ((++scannedFiles & 15) === 0)
3442
+ await onYield();
3242
3443
  if (!ERLANG_EXT.test(file))
3243
3444
  continue;
3244
3445
  const behaviour = moduleByFile.get(file);
@@ -3297,6 +3498,8 @@ function erlangBehaviourDispatchEdges(queries, ctx) {
3297
3498
  const edges = [];
3298
3499
  const seen = new Set();
3299
3500
  for (const file of ctx.getAllFiles()) {
3501
+ if ((++scannedFiles & 15) === 0)
3502
+ await onYield();
3300
3503
  if (!ERLANG_EXT.test(file))
3301
3504
  continue;
3302
3505
  const content = ctx.readFile(file);
@@ -3395,7 +3598,8 @@ function phpArrayBody(src, openIdx) {
3395
3598
  }
3396
3599
  return null;
3397
3600
  }
3398
- function laravelEventEdges(ctx) {
3601
+ async function laravelEventEdges(ctx, onYield) {
3602
+ let scannedFiles = 0;
3399
3603
  // event short name → its listener `handle` methods (deduped by node id).
3400
3604
  const listeners = new Map();
3401
3605
  const add = (event, handle) => {
@@ -3412,6 +3616,8 @@ function laravelEventEdges(ctx) {
3412
3616
  && n.startLine >= cls.startLine && n.startLine <= (cls.endLine ?? cls.startLine)) ?? null;
3413
3617
  // Pass 1 — build the event→handle map from both registration mechanisms.
3414
3618
  for (const file of ctx.getAllFiles()) {
3619
+ if ((++scannedFiles & 15) === 0)
3620
+ await onYield();
3415
3621
  if (!LARAVEL_PHP_EXT.test(file))
3416
3622
  continue;
3417
3623
  const content = ctx.readFile(file);
@@ -3457,6 +3663,8 @@ function laravelEventEdges(ctx) {
3457
3663
  const edges = [];
3458
3664
  const seen = new Set();
3459
3665
  for (const file of ctx.getAllFiles()) {
3666
+ if ((++scannedFiles & 15) === 0)
3667
+ await onYield();
3460
3668
  if (!LARAVEL_PHP_EXT.test(file))
3461
3669
  continue;
3462
3670
  const content = ctx.readFile(file);
@@ -3516,95 +3724,160 @@ async function synthesizeCallbackEdges(queries, ctx) {
3516
3724
  // that itself hangs (a real wedge) never reaches the next yield, so the
3517
3725
  // watchdog still catches that. See ./cooperative-yield.
3518
3726
  const yieldToLoop = (0, cooperative_yield_1.createYielder)();
3727
+ // Per-pass wall-clock timing to stderr, opt-in via CODEGRAPH_SYNTH_TIMINGS
3728
+ // (=1: passes over 250ms; =all: every pass). This is the diagnostic that
3729
+ // located both the #1091/#1122 watchdog stalls and the #1212 OOM — keep it.
3730
+ const markT = { t: Date.now() };
3731
+ const __mark = (label) => {
3732
+ const now = Date.now();
3733
+ const dt = now - markT.t;
3734
+ markT.t = now;
3735
+ if (process.env.CODEGRAPH_SYNTH_TIMINGS && (dt > 250 || process.env.CODEGRAPH_SYNTH_TIMINGS === 'all')) {
3736
+ console.error(`[synth-timing] ${label}: ${dt}ms`);
3737
+ }
3738
+ };
3739
+ // Language gating: one indexed DISTINCT over the files table lets a pass
3740
+ // whose own filters reference a specific language/extension be skipped
3741
+ // outright when the project has no such files — its result is provably
3742
+ // empty, so skipping is behavior-identical and the cost drops to zero
3743
+ // (the Kotlin pass was the OOM culprit on the pure-C Linux kernel, #1212).
3744
+ // Passes without an explicit language filter always run.
3745
+ const langs = queries.getDistinctFileLanguages();
3746
+ const has = (...ls) => ls.some((l) => langs.has(l));
3747
+ const JS_FAMILY = ['typescript', 'javascript', 'tsx', 'jsx'];
3748
+ const NONE = [];
3519
3749
  // Cross-file Go method→type `contains` edges must be synthesized AND persisted
3520
3750
  // FIRST: a method declared in a different file from its receiver type is
3521
3751
  // otherwise orphaned from the struct, and goImplementsEdges (next) derives a
3522
3752
  // struct's method set from its `contains` edges — so without this it would
3523
3753
  // under-count the interfaces a cross-file struct satisfies. (#583)
3524
- const goMethodContains = goCrossFileMethodContainsEdges(queries);
3525
- if (goMethodContains.length > 0)
3526
- queries.insertEdges(goMethodContains);
3754
+ const goMethodContains = has('go') ? await goCrossFileMethodContainsEdges(queries, yieldToLoop) : NONE;
3755
+ for (let i = 0; i < goMethodContains.length; i += 2000) {
3756
+ queries.insertEdges(goMethodContains.slice(i, i + 2000));
3757
+ await yieldToLoop();
3758
+ }
3527
3759
  await yieldToLoop();
3760
+ __mark('goMethodContains');
3528
3761
  // Go implicit `implements` edges must be synthesized AND persisted next: the
3529
3762
  // interface-dispatch bridge below reads `implements` edges from the DB, and
3530
3763
  // Go has none statically. (Other languages already have static implements
3531
3764
  // edges from extraction, so they don't need this pre-pass.)
3532
- const goImpl = goImplementsEdges(queries);
3533
- if (goImpl.length > 0)
3534
- queries.insertEdges(goImpl);
3765
+ const goImpl = has('go') ? await goImplementsEdges(queries, yieldToLoop) : NONE;
3766
+ for (let i = 0; i < goImpl.length; i += 2000) {
3767
+ queries.insertEdges(goImpl.slice(i, i + 2000));
3768
+ await yieldToLoop();
3769
+ }
3535
3770
  await yieldToLoop();
3771
+ __mark('goImplements');
3536
3772
  const fieldEdges = await fieldChannelEdges(queries, ctx, yieldToLoop);
3537
3773
  await yieldToLoop();
3774
+ __mark('fieldEdges');
3538
3775
  const closureCollEdges = await closureCollectionEdges(queries, ctx, yieldToLoop);
3539
3776
  await yieldToLoop();
3777
+ __mark('closureCollEdges');
3540
3778
  const emitterEdges = await eventEmitterEdges(ctx, yieldToLoop);
3541
3779
  await yieldToLoop();
3542
- const renderEdges = reactRenderEdges(queries, ctx);
3780
+ __mark('emitterEdges');
3781
+ const renderEdges = await reactRenderEdges(queries, ctx, yieldToLoop);
3543
3782
  await yieldToLoop();
3783
+ __mark('renderEdges');
3544
3784
  const jsxEdges = await reactJsxChildEdges(ctx, yieldToLoop);
3545
3785
  await yieldToLoop();
3546
- const vueEdges = vueTemplateEdges(ctx);
3786
+ __mark('jsxEdges');
3787
+ const vueEdges = has('vue') ? await vueTemplateEdges(ctx, yieldToLoop) : NONE;
3547
3788
  await yieldToLoop();
3548
- const svelteKitEdges = svelteKitLoadEdges(ctx);
3789
+ __mark('vueEdges');
3790
+ const svelteKitEdges = has('svelte') ? await svelteKitLoadEdges(ctx, yieldToLoop) : NONE;
3549
3791
  await yieldToLoop();
3550
- const pascalEdges = pascalFormEdges(ctx);
3792
+ __mark('svelteKitEdges');
3793
+ const pascalEdges = await pascalFormEdges(ctx, yieldToLoop);
3551
3794
  await yieldToLoop();
3552
- const flutterEdges = flutterBuildEdges(queries, ctx);
3795
+ __mark('pascalEdges');
3796
+ const flutterEdges = has('dart') ? await flutterBuildEdges(queries, ctx, yieldToLoop) : NONE;
3553
3797
  await yieldToLoop();
3554
- const arkuiStateEdges = arkuiStateBuildEdges(queries, ctx);
3798
+ __mark('flutterEdges');
3799
+ const arkuiStateEdges = has('arkts') ? await arkuiStateBuildEdges(queries, ctx, yieldToLoop) : NONE;
3555
3800
  await yieldToLoop();
3556
- const arkuiEmitter = arkuiEmitterEdges(ctx);
3801
+ __mark('arkuiStateEdges');
3802
+ const arkuiEmitter = has('arkts') ? await arkuiEmitterEdges(ctx, yieldToLoop) : NONE;
3557
3803
  await yieldToLoop();
3558
- const arkuiRoutes = arkuiRouterEdges(ctx);
3804
+ __mark('arkuiEmitter');
3805
+ const arkuiRoutes = has('arkts') ? await arkuiRouterEdges(ctx, yieldToLoop) : NONE;
3559
3806
  await yieldToLoop();
3560
- const cppEdges = cppOverrideEdges(queries);
3807
+ __mark('arkuiRoutes');
3808
+ const cppEdges = has('cpp') ? await cppOverrideEdges(queries, yieldToLoop) : NONE;
3561
3809
  await yieldToLoop();
3562
- const ifaceEdges = interfaceOverrideEdges(queries);
3810
+ __mark('cppEdges');
3811
+ const ifaceEdges = has('java', 'kotlin', 'csharp', 'swift', 'scala', 'go', 'rust', 'arkts', ...JS_FAMILY)
3812
+ ? await interfaceOverrideEdges(queries, yieldToLoop) : NONE;
3563
3813
  await yieldToLoop();
3564
- const kotlinExpectActual = kotlinExpectActualEdges(queries);
3814
+ __mark('ifaceEdges');
3815
+ const kotlinExpectActual = has('kotlin') ? await kotlinExpectActualEdges(queries, yieldToLoop) : NONE;
3565
3816
  await yieldToLoop();
3566
- const goGrpcEdges = goGrpcStubImplEdges(queries);
3817
+ __mark('kotlinExpectActual');
3818
+ const goGrpcEdges = has('go') ? await goGrpcStubImplEdges(queries, yieldToLoop) : NONE;
3567
3819
  await yieldToLoop();
3568
- const rnEventEdgesList = rnEventEdges(ctx);
3820
+ __mark('goGrpcEdges');
3821
+ const rnEventEdgesList = has(...JS_FAMILY) ? await rnEventEdges(ctx, yieldToLoop) : NONE;
3569
3822
  await yieldToLoop();
3570
- const fabricNativeEdges = fabricNativeImplEdges(ctx);
3823
+ __mark('rnEventEdgesList');
3824
+ const fabricNativeEdges = await fabricNativeImplEdges(ctx, yieldToLoop);
3571
3825
  await yieldToLoop();
3572
- const expoXPlatEdges = expoCrossPlatformEdges(queries);
3826
+ __mark('fabricNativeEdges');
3827
+ const expoXPlatEdges = await expoCrossPlatformEdges(queries, yieldToLoop);
3573
3828
  await yieldToLoop();
3574
- const rnXPlatEdges = rnCrossPlatformEdges(queries);
3829
+ __mark('expoXPlatEdges');
3830
+ const rnXPlatEdges = await rnCrossPlatformEdges(queries, yieldToLoop);
3575
3831
  await yieldToLoop();
3576
- const mybatisEdges = mybatisJavaXmlEdges(queries);
3832
+ __mark('rnXPlatEdges');
3833
+ const mybatisEdges = has('java', 'kotlin') && has('xml') ? await mybatisJavaXmlEdges(queries, yieldToLoop) : NONE;
3577
3834
  await yieldToLoop();
3578
- const ginEdges = ginMiddlewareChainEdges(queries, ctx);
3835
+ __mark('mybatisEdges');
3836
+ const ginEdges = has('go') ? await ginMiddlewareChainEdges(queries, ctx, yieldToLoop) : NONE;
3579
3837
  await yieldToLoop();
3580
- const thunkEdges = reduxThunkEdges(queries, ctx);
3838
+ __mark('ginEdges');
3839
+ const thunkEdges = has(...JS_FAMILY) ? await reduxThunkEdges(queries, ctx, yieldToLoop) : NONE;
3581
3840
  await yieldToLoop();
3841
+ __mark('thunkEdges');
3582
3842
  const registryEdges = await objectRegistryEdges(ctx, yieldToLoop);
3583
3843
  await yieldToLoop();
3584
- const rtkEdges = rtkQueryEdges(queries, ctx);
3844
+ __mark('registryEdges');
3845
+ const rtkEdges = has(...JS_FAMILY) ? await rtkQueryEdges(queries, ctx, yieldToLoop) : NONE;
3585
3846
  await yieldToLoop();
3586
- const piniaEdges = piniaStoreEdges(ctx);
3847
+ __mark('rtkEdges');
3848
+ const piniaEdges = has('vue', ...JS_FAMILY) ? await piniaStoreEdges(ctx, yieldToLoop) : NONE;
3587
3849
  await yieldToLoop();
3588
- const vuexEdges = vuexDispatchEdges(ctx);
3850
+ __mark('piniaEdges');
3851
+ const vuexEdges = has('vue', ...JS_FAMILY) ? await vuexDispatchEdges(ctx, yieldToLoop) : NONE;
3589
3852
  await yieldToLoop();
3590
- const celeryEdges = celeryDispatchEdges(ctx);
3853
+ __mark('vuexEdges');
3854
+ const celeryEdges = has('python') ? await celeryDispatchEdges(ctx, yieldToLoop) : NONE;
3591
3855
  await yieldToLoop();
3592
- const springEdges = springEventEdges(ctx);
3856
+ __mark('celeryEdges');
3857
+ const springEdges = has('java') ? await springEventEdges(ctx, yieldToLoop) : NONE;
3593
3858
  await yieldToLoop();
3594
- const mediatrEdges = mediatrDispatchEdges(ctx);
3859
+ __mark('springEdges');
3860
+ const mediatrEdges = has('csharp') ? await mediatrDispatchEdges(ctx, yieldToLoop) : NONE;
3595
3861
  await yieldToLoop();
3596
- const sidekiqEdges = sidekiqDispatchEdges(ctx);
3862
+ __mark('mediatrEdges');
3863
+ const sidekiqEdges = has('ruby') ? await sidekiqDispatchEdges(ctx, yieldToLoop) : NONE;
3597
3864
  await yieldToLoop();
3598
- const erlangBehaviourEdges = erlangBehaviourDispatchEdges(queries, ctx);
3865
+ __mark('sidekiqEdges');
3866
+ const erlangBehaviourEdges = has('erlang') ? await erlangBehaviourDispatchEdges(queries, ctx, yieldToLoop) : NONE;
3599
3867
  await yieldToLoop();
3600
- const laravelEdges = laravelEventEdges(ctx);
3868
+ __mark('erlangBehaviourEdges');
3869
+ const laravelEdges = has('php') ? await laravelEventEdges(ctx, yieldToLoop) : NONE;
3601
3870
  await yieldToLoop();
3602
- const cFnPtrEdges = (0, c_fnptr_synthesizer_1.cFnPointerDispatchEdges)(queries, ctx);
3871
+ __mark('laravelEdges');
3872
+ const cFnPtrEdges = has('c', 'cpp') ? await (0, c_fnptr_synthesizer_1.cFnPointerDispatchEdges)(queries, ctx, yieldToLoop) : NONE;
3603
3873
  await yieldToLoop();
3604
- const goframeEdges = (0, goframe_synthesizer_1.goframeRouteEdges)(ctx);
3874
+ __mark('cFnPtrEdges');
3875
+ const goframeEdges = has('go') ? await (0, goframe_synthesizer_1.goframeRouteEdges)(ctx, yieldToLoop) : NONE;
3605
3876
  await yieldToLoop();
3606
- const nixOptionEdges = await nixOptionPathEdges(queries, yieldToLoop);
3877
+ __mark('goframeEdges');
3878
+ const nixOptionEdges = has('nix') ? await nixOptionPathEdges(queries, yieldToLoop) : NONE;
3607
3879
  await yieldToLoop();
3880
+ __mark('nixOptionEdges');
3608
3881
  const merged = [];
3609
3882
  const seen = new Set();
3610
3883
  for (const e of [
@@ -3651,8 +3924,15 @@ async function synthesizeCallbackEdges(queries, ctx) {
3651
3924
  seen.add(key);
3652
3925
  merged.push(e);
3653
3926
  }
3654
- if (merged.length > 0)
3655
- queries.insertEdges(merged);
3927
+ __mark('dedupe-merge');
3928
+ // Chunked insert with yields: on the Linux kernel the merged synthesized
3929
+ // edge set is ~275k rows, and one transaction for all of them was a 20s
3930
+ // unyielded main-thread span (#1212 follow-up) — the last one in the tail.
3931
+ for (let i = 0; i < merged.length; i += 2000) {
3932
+ queries.insertEdges(merged.slice(i, i + 2000));
3933
+ await yieldToLoop();
3934
+ }
3935
+ __mark('insertMergedEdges');
3656
3936
  return merged.length + goImpl.length + goMethodContains.length;
3657
3937
  }
3658
3938
  //# sourceMappingURL=callback-synthesizer.js.map