Skip to content

perf(nav): reduce code-rank path canonicalization and membership overhead - #12

Draft
ClaudiuCeia with Copilot wants to merge 2 commits into
mainfrom
copilot/perf-nav-reduce-code-rank-overhead
Draft

ClaudiuCeia with Copilot wants to merge 2 commits into
mainfrom
copilot/perf-nav-reduce-code-rank-overhead

Conversation

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown

Each rankCode run was calling realpathSync on every reference file path — including repeats — and using Array.includes for O(n²) target deduplication in createService.

Changes

packages/nav/src/service.ts

  • Set-based deduplication: fileNames.includes(resolved)fileNameSet.has(resolved), making target membership O(1) after setup
  • createCachedBoundaryChecker(boundary) (new export): returns a (path: string) => boolean closure backed by a Map cache — each distinct path hits realpathSync at most once per checker lifetime

packages/nav/src/code-rank/rank.ts

  • Creates one isWithinBoundary checker per rankCode call; passes it into collectReferenceStats as a plain predicate
  • collectReferenceStats signature drops the boundary object in favor of (filePath: string) => boolean — simpler and cache-aware
// Before: realpathSync called on every reference.fileName
if (!isPathWithinWorkspaceBoundary(boundary, reference.fileName)) { ... }

// After: cached per rankCode run
const isWithinBoundary = createCachedBoundaryChecker(boundary);
// ...
if (!isWithinBoundary(reference.fileName)) { ... }

Benchmark

  • bench/suites/fixtures.ts: adds createCodeRankFixture — hub-and-spoke TS workspace (one hub with N×M exports, N spoke files each calling their slice)
  • bench/suite.ts: new nav/code-rank group benchmarking 50-file × 4-export fixture

Tests

  • service.test.ts: unit tests for createCachedBoundaryChecker — inside paths, outside paths, symlinks resolving outside the boundary
  • code-rank.test.ts: symlinked files resolving outside the git boundary are excluded from referencingFiles; symbol deduplication produces no duplicate entries

- Replace Array.includes with Set in createService target-file deduplication
- Export createCachedBoundaryChecker from service.ts for per-run path
  canonicalization caching (each distinct path resolved via realpathSync
  at most once per rankCode call)
- Use createCachedBoundaryChecker in rankCode / collectReferenceStats
- Add createCodeRankFixture helper to bench/suites/fixtures.ts
- Add nav/code-rank benchmark group to bench/suite.ts
- Add createCachedBoundaryChecker unit tests in service.test.ts
- Add symlink filtering and canonical-path deduplication tests in code-rank.test.ts
Copilot AI changed the title [WIP] Optimize code-rank path and membership checks perf(nav): reduce code-rank path canonicalization and membership overhead Jul 25, 2026
Copilot AI requested a review from ClaudiuCeia July 25, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(nav): reduce code-rank path and membership overhead

2 participants