Commit f6bd74e
authored
perf: sub-100ms incremental rebuilds (466ms → 67-80ms) (#644)
* fix: db version warning, barrel export tracing, quieter tsconfig, Set compat
9.1 — Warn on graph load when DB was built with a different codegraph
version. The check runs once per process in openReadonlyOrFail() and
suggests `build --no-incremental`.
9.2 — Barrel-only files now emit reexport edges during build. Previously
the entire file was skipped in buildImportEdges; now only non-reexport
imports are skipped, so `codegraph exports` can follow re-export chains.
9.3 — Demote "Failed to parse tsconfig.json" from warn to debug level
so it no longer clutters every build output.
9.4 — Document EXTENSIONS/IGNORE_DIRS Array→Set breaking change in
CHANGELOG. Add .toArray() convenience method and export ArrayCompatSet
type for consumers migrating from the pre-3.4 array API.
* docs: soften EXTENSIONS/IGNORE_DIRS changelog wording
* fix: address review feedback — version check, Set mutation, barrel edge duplication (#634)
- Move _versionWarned flag outside mismatch conditional to avoid
redundant build_meta queries when versions match.
- Wrap SUPPORTED_EXTENSIONS in new Set() to avoid mutating the
sibling module's export.
- Delete outgoing edges for barrel-only files before re-adding them
to fileSymbols during incremental builds, preventing duplicate
reexport edges.
* refactor: replace vendor.d.ts with @types/better-sqlite3
Delete the 39-LOC manual ambient type declarations for better-sqlite3
and use the community @types/better-sqlite3 package instead. The vendor
file was a migration-era shim (allowJs is long gone from tsconfig).
- Replace all BetterSqlite3.Database → BetterSqlite3Database (types.ts)
- Replace all BetterSqlite3.Statement → SqliteStatement (types.ts)
- Simplify constructor casts in connection.ts, branch-compare.ts,
snapshot.ts (no longer needed with proper @types)
- Clean up watcher.ts double-cast and info.ts @ts-expect-error
- Widen transaction() return type for @types compatibility
* fix: address Greptile review feedback
- Restore warn level for tsconfig/jsconfig parse errors (P1: was
incorrectly downgraded to debug; ENOENT is already guarded by
existsSync before the try block)
- Simplify openReadonlyOrFail constructor cast to match openDb pattern (P2)
- Use Object.assign in withArrayCompat instead of cast-then-mutate (P2)
- Remove unused BetterSqlite3Database import from branch-compare.ts
- Remove stale biome-ignore suppression from snapshot.ts
* fix: preserve transaction argument types via inline inference (#640)
* perf: sub-100ms 1-file incremental rebuilds (466ms → 78-90ms)
Four optimizations for small incremental builds (≤5 changed files):
1. Scope barrel re-parsing to related barrels only (resolve-imports.ts)
Instead of parsing ALL barrel files one-by-one (~93ms), only re-parse
barrels imported by or re-exporting from changed files, batch-parsed
in one call (~11ms).
2. Fast-path structure metrics (build-structure.ts)
For ≤5 changed files on large codebases (>20 files), use targeted
per-file SQL queries (~2ms) instead of loading ALL definitions from
DB and recomputing ALL metrics (~35ms).
3. Skip unnecessary finalize work (finalize.ts)
- Skip setBuildMeta writes for ≤5 files (avoids WAL transaction)
- Skip drift detection for ≤3 files
- Skip auto-registration dynamic import for incremental builds
- Move timing measurement before db.close()
4. Deferred db.close() for small incremental builds (connection.ts)
WAL checkpoint in db.close() costs ~250ms on Windows NTFS. Defer to
next event loop tick so buildGraph() returns immediately. Includes
flushDeferredClose() for test compatibility and auto-flush on openDb().
* perf: scope node loading and skip filesystem scan for incremental builds
Two optimizations for small incremental builds (≤5 changed files):
1. collectFiles: reconstruct file list from DB file_hashes + journal
deltas instead of full recursive filesystem scan (~7ms savings)
2. buildEdges: scope node loading query to only relevant files (changed
files + import targets) with lazy SQL fallback for global name
lookups (~5ms savings on 6K→400 nodes)
Combined improvement: 78-90ms → 67-80ms for 1-file incremental on
473-file codebase.
* fix: align scopedLoad gate with loadNodes to prevent missing lazy fallback (#644)
Return scoped flag directly from loadNodes instead of re-deriving it
with a different threshold, ensuring addLazyFallback is always called
when the query was actually scoped.
* fix: align drift detection and metadata persistence thresholds, remove tmpdir shadow (#644)
- Lower setBuildMeta gate from >5 to >3 to match drift detection gate,
preventing stale baseline counts after series of 4-5 file builds.
- Remove redundant dynamic import of tmpdir (already imported statically).
- Add comment clarifying finalizeMs metric placement.1 parent 21d1b83 commit f6bd74e
3 files changed
Lines changed: 162 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
561 | 561 | | |
562 | 562 | | |
563 | 563 | | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
564 | 632 | | |
565 | 633 | | |
566 | 634 | | |
567 | 635 | | |
568 | 636 | | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
575 | 640 | | |
576 | 641 | | |
577 | 642 | | |
| |||
592 | 657 | | |
593 | 658 | | |
594 | 659 | | |
595 | | - | |
| 660 | + | |
596 | 661 | | |
597 | 662 | | |
598 | 663 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
8 | | - | |
| 10 | + | |
9 | 11 | | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
13 | 77 | | |
14 | 78 | | |
15 | 79 | | |
| |||
33 | 97 | | |
34 | 98 | | |
35 | 99 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 100 | + | |
41 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
42 | 119 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
| |||
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
160 | 166 | | |
161 | 167 | | |
162 | 168 | | |
| |||
177 | 183 | | |
178 | 184 | | |
179 | 185 | | |
180 | | - | |
181 | 186 | | |
182 | 187 | | |
183 | 188 | | |
| |||
0 commit comments