Repository navigation
fix(project): batch Git ignore checks per directory level - #60
Merged
Merged
Conversation
Preparing provider exclusions asked Git once per parent directory: one `git check-ignore` for its children, plus one `git ls-files` for each ignored child. On Kubernetes that is about 2,200 serial Git processes and 29 s before gopls receives its first workspace generation (1lck/Lithe-IDEA#1994). Prefetch the same answers a directory level at a time: one `check-ignore` per level and repository, and one batched `ls-files` (the new `lithe_git::tracked_directories`) for the ignored children. Walks still record decisions per parent through `prepare_parent`, which takes them from the prefetch only when every candidate was answered there and otherwise asks Git as before, so the excluded roots that providers and the indexing status see do not change. Provider preparation, snapshots and search index builds prefetch with their own visibility rules; releasing the last lease frees the prefetched answers along with the decisions. Kubernetes: 29.2 s and 2,179 Git processes before, 3.1 s and 14 after, with identical file lists. The Lithe-IDEA checkout keeps the same seven excluded roots with 9 Git processes instead of 59.
2 tasks done
xiaoyumuxi
marked this pull request as ready for review
November 15, 2026 20:04
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue / Linked issue
Lithe-IDEA 升级
PINNED_CORE_REVISION到包含本修复的 commit 后,由那个 PR 关闭 #1994。PR 类型 / Type
改动说明 / What changes
背景 / Why
在 Lithe 里打开 Kubernetes 这类大型 Go 仓库,gopls 要等约 30 秒才开始工作。原因是语言服务器启动前,
lsp-engine先调用lithe_project::indexing::prepare_provider_exclusions算出 Git 忽略的目录,作为 gopls 的directoryFilters。旧实现为每个父目录串行运行一次git check-ignore --stdin -z,被忽略的子目录再各运行一次git ls-files,Git 进程数与目录数成正比:Kubernetes 上要 2,179 个进程、29.2 秒。本 PR 把这些问题改成按目录层批量询问,进程数只与目录深度和仓库数有关,算出的排除结果不变。
改动 / Changes
lithe-git(rust/crates/git/src/status.rs)tracked_directories(directory, directories):沿用现有的pathspec_batches/LS_FILES_PATHSPEC_BUDGET分批,一次git --literal-pathspecs ls-files -z回答一批目录下有没有已跟踪内容。gitlink 输出目录本身,普通文件输出其后代,两种都会归到对应目录。None,调用方回退到逐目录询问。lithe-project索引策略(rust/crates/project/src/indexing.rs)IndexingContext新增两个字段,configure、rollback_failed_policy、refreshed_context三处构造新的一代时都重置为空:prefetched:预取到的 Git 答案;prefetched_scopes:已经预取过的可见性规则,它的锁同时让预取串行执行。prefetch_git_answers(rules):.git的目录,没有则用工作区根),每层每个仓库只运行一次check-ignore。tracked_directories判断。prepare_parent相同:嵌套仓库或未被忽略的目录保留;被忽略但含已跟踪内容的目录保留;其余排除。decisions或之前的预取)的目录不再重复询问。decisions:prepare_parent只在一个父目录的所有候选子目录都有预取答案时才采用;有任何缺失(例如预取之后新建的目录)就按原路径逐目录询问 Git。excluded_roots(gopls 的directoryFilters)和索引状态看到的排除集合与原来一致。check-ignore失败的答案仍按原规则:该目录记为保留,并设置git_failed。prepare_provider_exclusions在prepare_parent(root, "")之前,用与随后快照相同的内置规则预取。release_lease在最后一个租约释放时,和decisions一起清空prefetched。退役的记录会继续留在表里用来取消迟到的读者,不清空会一直占着与目录数同量级的内存。prepare_parent的尾部逻辑抽成store_decisions,行为不变。快照与搜索索引(
files/snapshot.rs、search_index.rs)snapshot和WorkspaceSearchIndex::build遍历前,用各自的可见性规则预取;随后遍历时reason→prepare_parent直接复用这些答案。回归测试
indexing::tests::provider_preparation_asks_git_per_directory_level_not_per_parent(#[cfg(unix)]).gitignore忽略generated/;pkg0/mod0/generated/Tracked.txt用git add -f跟踪;pkg1/nested是一个嵌套仓库,用自己的规则忽略cache/。GitExecutionOptions.executable指向一个包装脚本,统计 Git 进程数。excluded_roots与逐目录询问的结果一致:有已跟踪文件的pkg0/mod0/generated保留,只排除其下的out,嵌套仓库的cache被排除;git_failed未被设置;check-ignore不超过 5 次、ls-files不超过 3 次;不在本 PR 范围内 / Out of scope
scripts/desktop/build-desktop-core.sh的PINNED_CORE_REVISION升到本修复合入后的 Core commit,在桌面端复测 gopls 启动延迟,并关闭 [Bug] 大型 Git 仓库中 Core 启动语言服务器前逐个目录执行 git check-ignore,Kubernetes 上 gopls 晚约 30 秒才启动 1lck/Lithe-IDEA#1994。本 PR 合入后另开。类型专属:fix
复现与根因
gitIgnoreEnabled: true配置索引策略,然后调用prepare_provider_exclusions。git check-ignore,这段时间里 gopls 收不到第一代工作区设置。prepare_parent按父目录逐个询问 Git,每次都要新起一个进程,并且是串行的。检查项
rust/crates/project/src/indexing.rs中的provider_preparation_asks_git_per_directory_level_not_per_parent。check-ignore ran 76 times, ls-files 33 times,耗时 1.82 s。prepare_parent只有两个调用方:prepare_provider_exclusions和reason,后者被is_excluded用于快照、搜索索引和目录列表。lithe_git::ignored_paths签名未变,另外两个调用方(history.rs、search_everywhere.rs)不受影响。lsp-engine只用prepare_provider_exclusions和excluded_roots(engine.rs、configuration.rs、scan_settings.rs),接口未变。store_decisions只是为了让两条路径共用写入逻辑。.agents/notes/implemented/bug-fix/。“不得按目录逐个启动 Git 进程”这条约束由回归测试里的进程数断言守住。范围检查 / Scope checks
git_failed降级路径,没有新增事件;generate-log-events.mjs --check通过。prefetched每个目录一项,与已有的decisions同量级;索引换代时重建,最后一个租约释放时清空。验证 / Verification
本机为 Apple M4、24 GB 内存,Rust 1.100.0,Git 2.56.1。
cargo fmt --manifest-path rust/Cargo.toml --all -- --checknode scripts/logging/generate-log-events.mjs --checkscripts/rust-core/verify-rust-core-comments.sh core git lsp-engine projectnode scripts/rust-core/verify-platform-tests.mjscargo test --locked --manifest-path rust/Cargo.toml -p lithe-core -p lithe-git -p lithe-lsp-engine -p lithe-projectcargo clippy --locked …(同上 4 个包)--all-targets --all-features -- -D warningscargo clippy --locked …(同上 4 个包)--all-targets --target x86_64-pc-windows-msvc -- -D warningscheck-ignore ran 76 times, ls-files 33 times改动前后基线。 测量方法:
indexing::configure(gitIgnoreEnabled: true),再对prepare_provider_exclusions计时。excluded_roots和快照文件列表。GitExecutionOptions.executable指向的计数包装脚本单独再跑一遍统计。prepare_provider_exclusionscheck-ignorels-files.artifacts、.claude/worktrees、.codex、.idea、.lithe、dist、shared/fixtures)。未能执行的检查和原因:
scripts/rust-core/affected-crates.mjs对本改动只选了 Linux 作业,没有 macOS / Windows 原生作业,所以 CI 也不会在 Windows 上运行这些测试。PINNED_CORE_REVISION,放在后续 PR 里做。提交前确认 / Final checks
main(5802c42)创建,目标分支main。