Commit 8e78e62
authored
fix: free leaked WASM trees in native engine typeMap backfill (#534)
* perf: reduce query latency regression from 3.1.4 → 3.3.0
Three targeted fixes for the +28–56% query latency regression:
1. Pin benchmark hub target to stable function names (buildGraph,
openDb, loadConfig) instead of auto-selecting the most-connected
node. Barrel/type files becoming the hub made version-to-version
comparison meaningless.
2. Gate implementors queries in bfsTransitiveCallers — check once
whether the graph has any 'implements' edges before doing per-node
findNodeById + findImplementors lookups. Skips all implementor
overhead for codebases without interface/trait hierarchies.
3. Cache loadConfig() results per cwd. The config file is read from
disk on every fnImpactData and diffImpactData call; caching
eliminates redundant fs.existsSync + readFileSync + JSON.parse
per query invocation.
Impact: 5 functions changed, 123 affected
* fix: return structuredClone from config cache and guard benchmark db handle
Prevent callers from mutating the cached config object by returning a
deep clone on cache hits. Add try/finally to selectTargets() so the
database handle is closed even if a query throws.
Impact: 2 functions changed, 1 affected
* fix: install @huggingface/transformers in npm-mode benchmark workers
The embedding benchmark's npm mode installs codegraph into a temp dir,
but @huggingface/transformers is a devDependency and not included.
All 6 model workers crash on import, producing symbols: 0, models: {}.
Install it explicitly from the local devDependencies version, matching
the existing pattern for native platform packages. Also add a guard in
update-embedding-report.js to reject empty results and fail loudly
instead of silently overwriting valid benchmark data.
* fix: free leaked WASM trees in native engine typeMap backfill
The typeMap backfill path in parseFilesAuto and backfillTypeMap called
wasmExtractSymbols but never freed the returned WASM tree objects.
Over repeated builds (benchmarks, watch mode), hundreds of trees
accumulated in WASM linear memory, eventually corrupting V8 state and
crashing the native addon with ACCESS_VIOLATION / has_exception().
Two fixes:
1. Free WASM trees immediately after extracting typeMap data in both
backfillTypeMap() and the parseFilesAuto() bulk backfill loop.
2. Skip backfill entirely for JS files — only TS/TSX have type
annotations that WASM can extract. The native engine already
handles JS `new Expr()` patterns, so re-parsing all JS files
with WASM was pure waste.
Closes #530
Impact: 2 functions changed, 2 affected
* fix(native): align edge builder kind filters with JS parity
The Rust edge builder only matched `kind == "class"` when looking up
source nodes and targets for extends/implements edges. This caused all
`impl Trait for Struct` relationships (and any non-class hierarchy) to
be silently dropped — producing 0 implements edges for Rust sources
while WASM correctly found 9.
Align the three kind filter sets with the JS-side constants:
- Source: class, struct, record, enum (was: class only)
- Extends targets: class, struct, trait, record (was: class only)
- Implements targets: interface, class, trait (was: interface, class)
Fixes #530 (partial — implements parity gap)
Impact: 1 functions changed, 0 affected
* fix: address review feedback on WASM tree cleanup and JS backfill skip
- Consolidate duplicated tree.delete() in backfillTypeMap into a single
finally block, preventing future early-return paths from leaking trees
- Skip WASM typeMap backfill for JS files in parseFileAuto and
parseFileIncremental single-file paths, matching the bulk path behavior
Impact: 3 functions changed, 2 affected1 parent f8016c6 commit 8e78e62
2 files changed
Lines changed: 66 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
342 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
343 | 345 | | |
344 | 346 | | |
345 | 347 | | |
346 | 348 | | |
347 | 349 | | |
348 | | - | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
349 | 353 | | |
350 | 354 | | |
351 | 355 | | |
| |||
362 | 366 | | |
363 | 367 | | |
364 | 368 | | |
365 | | - | |
| 369 | + | |
366 | 370 | | |
367 | 371 | | |
368 | 372 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
404 | 415 | | |
405 | 416 | | |
406 | 417 | | |
| |||
441 | 452 | | |
442 | 453 | | |
443 | 454 | | |
444 | | - | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
445 | 462 | | |
446 | 463 | | |
447 | 464 | | |
| |||
486 | 503 | | |
487 | 504 | | |
488 | 505 | | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
501 | 534 | | |
502 | | - | |
503 | | - | |
504 | 535 | | |
505 | 536 | | |
506 | 537 | | |
| |||
578 | 609 | | |
579 | 610 | | |
580 | 611 | | |
581 | | - | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
582 | 619 | | |
583 | 620 | | |
584 | 621 | | |
| |||
0 commit comments