Repository navigation
Description
Problem or Motivation
GitignoreIndex.is_ignored (src/devops_cli/core/gitignore.py:132) evaluates every parent folder of a path from the repository root at each call. For each parent and each ignore file in scope, _match calls Path.relative_to, and _relative calls it one more time. In Python 3.14, Path.relative_to walks Path.parents and makes a new Path for each parent, so each call is slow.
Measured on this repository after #4662: the code graph walk asks about 3,719 folders and takes about 4.5 s at load average 10. A cProfile run of the walk gave 23.7 s in total under the profiler: 18.8 s in is_ignored, 8.5 s of that in pathlib.relative_to, and 5.0 s in the Sequence.__contains__ of Path.parents. The same index serves the RAG indexer walk (ai/rag/indexer.py:748) and the file watcher (watchers/file_watcher.py:59), which also ask about each folder.
Proposed Solution & Architectural Design
- Make the relative path once with
os.pathstring operations, and give each ignore file its base as a string prefix, not as aPath.relative_tocall. - Optional: let a walk ask about a folder whose parent it already found not ignored, so that
is_ignoredchecks only the last part.
Risk: Low. The ignore rules and pathspec stay the same. The contract tests of the index keep the verdicts.
Target Subsystem
Core (src/devops_cli/core/gitignore.py).
Existing Tool Considered
pathspec already gives git's wildmatch rules, and it stays. git check-ignore --stdin gives the verdicts of git itself, but it starts a process, and the index exists to avoid that (39.5 ms for each file when it spawned git). The standard library os.path covers the change. Cost: about 20,000 tokens and 1 hour.
Acceptance Criteria
- The walk of the code graph over this repository asks the same folders and gives the same files, in less than half of its time before the change (measured in one process, old and new code one after the other).
- The tests of
core/gitignore.pypass with no change to their verdicts.
Dependencies
None.
Source: #5039
Alternatives check of 2026-11-15: not-applicable.
Class: perf, no search.
Tool: none found.
Proposed design
Problem statement
The ignore index evaluates each parent folder of a path from the repository root at each call. For each parent and each ignore file in scope, _match calls Path.relative_to, and _relative calls it once more. In Python 3.14 each call builds a new Path for each parent, so the call is slow. A profile of the code graph walk records 18.8 s in is_ignored, and 8.5 s of that in pathlib.relative_to. The change computes the relative path once with os.path string operations. Every ignore verdict stays the same.
Acceptance criteria
Requirement: String paths in the ignore evaluation
GitignoreIndex.is_ignored MUST compute the path relative to the repository root with os.path string operations and MUST NOT call Path.relative_to for each parent folder.
Scenario: A walk makes no Path.relative_to call for a parent
- WHEN A test walks a fixture tree of 500 folders through
is_ignoredand counts each call topathlib.Path.relative_to. - THEN The count is zero and each
is_ignoredcall returns a bool.
Requirement: Ignore verdicts stay the same
The index MUST return the same ignore verdict for each path and is_dir value as the implementation before the change.
Scenario: The index contract tests pass with no change
- WHEN
tests/core/test_gitignore_evaluation.pyruns against the new implementation with no change to its expectations. - THEN Every test in the file passes.
Requirement: The folder walk keeps its file set
The folder walk that calls is_ignored MUST ask the same folders and MUST return the same files as before the change.
Scenario: A walk of a fixture repository returns the recorded file list
- WHEN The walk runs over a fixture repository with nested
.gitignorefiles and one ignored folder. - THEN The returned file list equals the list recorded before the change.
Requirement: The folder walk time halves
The folder walk that calls is_ignored MUST take less than half of the time it took before the change, measured in one process on the same tree.
Scenario: A benchmark walk on a fixture tree is at least twice as fast
- WHEN A benchmark runs the walk over a fixture tree of 3,000 folders with the new code and with a reference copy of the old loop in one process.
- THEN The new code takes less than half of the time of the reference copy.
Existing Tool Considered
The alternatives check of 2026-11-15 recorded not-applicable for this perf item and ran no search, so it names no tool. pathspec stays as the matcher: it covers git's wildmatch rules in the process and lacks no rule this change needs. git check-ignore --stdin gives git's own verdicts, but it starts a process (39.5 ms for each file), and the index exists to avoid that process. The change builds its own code: about 20,000 tokens and 1 hour to build, keep and fix it.
Key questions
- Where does the cost of
is_ignoredcome from?:GitignoreIndex.is_ignored(src/devops_cli/core/gitignore.py:132) walks each parent folder of the target from the repository root. For each parent and each ignore file in scope,_match(src/devops_cli/core/gitignore.py:182) callsPath.relative_to, and_relative(src/devops_cli/core/gitignore.py:119) calls it once more. [sources: src/devops_cli/core/gitignore.py:119, src/devops_cli/core/gitignore.py:132, src/devops_cli/core/gitignore.py:178, src/devops_cli/core/gitignore.py:182] - Which path operation replaces
Path.relative_tofor each parent?: Compute the path relative to the repository root once withos.path.relpathand passstrvalues topathspec. Compare each ignore file's base with a string prefix test. Build noPathobject for a parent. (best practice) [sources: src/devops_cli/core/gitignore.py:119, src/devops_cli/core/gitignore.py:132]- Chosen: os.path string operations.
os.path.relpathreturns astr, builds noPathfor each parent, andpathspecacceptsstrpaths. The standard library holds it. - Rejected: Build the
Path.parentstuple once for each target. It still builds aPathfor each parent and keeps theSequence.__contains__scan ofPath.parents, which the profile shows at 5.0 s. - Rejected: Cache the verdict of each parent folder. A cache needs an invalidation rule for each change of a
.gitignorefile. The string path removes the cost with no cache.
- Chosen: os.path string operations.
- Does the change keep
pathspecas the matcher?: Keeppathspec. It gives git's wildmatch rules in the process and stays the matcher of the index. Do not callgit check-ignore --stdinfor each path. (best practice) [sources: src/devops_cli/core/gitignore.py, src/devops_cli/ai/rag/indexer.py]- Chosen: Keep pathspec. It gives git's wildmatch rules in the process, and the change touches only the path handling around it.
- Rejected: Shell out to
git check-ignore --stdin. It starts a process for each ask. The body records 39.5 ms for each file when the index spawned git, and the index exists to avoid that.
- Does
is_ignoredget a parameter that says the parent folder is not ignored?: No. Keep the call shape of the walk in this change. The string path removes the measured cost, and the parameter changes the contract ofis_ignoredfor each caller, such assrc/devops_cli/core/repo.py:548. (best practice) [sources: src/devops_cli/core/gitignore.py:132, src/devops_cli/core/repo.py:548]- Chosen: Keep the current call shape. The string path removes the cost that the profile shows, and the acceptance criteria name no new parameter. Each caller keeps its code.
- Rejected: Add a parent-verdict parameter to
is_ignored. It changes the index contract and makes each walker carry the scope of the parent. That is a second change with its own correctness risk.
- How does the test hold the performance requirement?: The required check counts each
Path.relative_tocall in a walk of a fixture tree and asserts the count is zero. A benchmark test runs the walk over a fixture tree of 3,000 folders with the new code and with a reference copy of the old loop in one process, and asserts the new code takes less than half of the time. (best practice) [sources: tests/core/test_gitignore_evaluation.py]- Chosen: Call count plus a benchmark ratio. The call count is stable on any machine, and the benchmark states the time target of the issue and runs offline.
- Rejected: Wall-clock ratio alone. One wall-clock ratio is noisy on a shared runner and gives a false failure.
- Rejected: A cProfile run of the walk. A profile run is heavy, and its numbers move with the load average of the machine.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 12, 2026
core, and .github/labels.yml declares no scope/core label. Add the label to the file to give the scope to this item.Both are perf changes in the same project, but #4662 targets regex compilation in ast graph while this targets path resolution in gitignore.py.devops-cli-service commentedon Nov 15, 2026
Alternatives check: not-applicable
Class: perf. The check makes no search and no model call for an item of this class.
Tool: none found
Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 16, 2026
Status set to Ready at 9cc974b (see proposed design in issue body).