Skip to content

refactor(core): build ancestor dirs incrementally during scan - #63453

Open
delaysystem wants to merge 1 commit into
anomalyco:devfrom
delaysystem:opt/scan-prefix-incremental
Open

delaysystem wants to merge 1 commit into
anomalyco:devfrom
delaysystem:opt/scan-prefix-incremental

Conversation

@delaysystem

Copy link
Copy Markdown

Issue for this PR

N/A — small performance refactor, no behavior change.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

While scanning, each file rebuilt every ancestor directory string with parts.slice(0, offset + 1).join("/") — O(depth²) slicing per file. This builds the same strings with a single incremental prefix pass, producing identical directory entries. Adds a test covering nested directory indexing.

Note: this touches packages/core/src/filesystem/search.ts in a hunk disjoint from the sibling PR from opt/find-index-cache. They are sequenced — if this one lands first, the other branch will rebase.

How did you verify your code works?

Ran the focused suite in packages/core:

bun test test/filesystem/search.test.ts
10 pass, 0 fail, 36 expect() calls

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The search change is sound. The new loop builds exactly the same ancestor directory keys as the old slice().join("/") loop: I checked both against edge-case paths (empty, leading /, //, ./, trailing /) and they matched. The focused search tests and the tsc type check for packages/core pass.

Public API: unchanged.

  • The branch also includes b8e5960e5, the Swift highlights pin from your #63165 (see inline). Please drop it here so each change is reviewed and merged once.
  • The new nested-directory test passes on the base too, since the refactor keeps behaviour the same. It can be dropped to keep this minimal.

Comment thread packages/tui/src/parsers-config.ts Outdated
// NOTE: Using parser repo queries instead of nvim-treesitter due to incompatible #lua-match? predicates
// "https://raw.githubusercontent.com/nvim-treesitter/nvim-treesitter/refs/heads/master/queries/highlights.scm
"https://raw.githubusercontent.com/alex-pinkus/tree-sitter-swift/main/queries/highlights.scm",
"https://raw.githubusercontent.com/alex-pinkus/tree-sitter-swift/0.7.1/queries/highlights.scm",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the Swift highlights fix from #63165 and has nothing to do with the search refactor (the description says nothing unrelated is included). Please drop this commit and the filetype.test.ts change from this branch and keep them in #63165.

Replace the O(depth^2) slice+join per file with a single incremental prefix pass producing identical strings. Adds a nested-dirs test.
@delaysystem
delaysystem force-pushed the opt/scan-prefix-incremental branch from 85f8519 to a319bf0 Compare November 12, 2026 04:57

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Swift highlights commit is gone and the branch is rebased onto the latest dev, so it now changes only the search refactor. The ancestor-directory loop is unchanged from the version I checked before (same keys as the old slice().join() loop). The focused search tests and the tsc type check for packages/core pass.

Public API: unchanged.

No new concerns. The new nested-directory test also passes on the base, so it can still be dropped to keep the change minimal.

This branch has not been deployed

No deployments
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.

1 participant