Skip to content

Avoid quadratic C header evidence scans - #1099

Open
Ha1baraA11 wants to merge 1 commit into
tirth8205:stagingfrom
Ha1baraA11:pr/code-review-graph-977
Open

Ha1baraA11 wants to merge 1 commit into
tirth8205:stagingfrom
Ha1baraA11:pr/code-review-graph-977

Conversation

@Ha1baraA11

Copy link
Copy Markdown

Linked issue

Fixes #977

What & why

  • The C-header evidence scan called _is_in_static_dead_guard() for every syntax
    node. On long nested #elif chains, each call rescanned ancestors. This PR
    carries dead-branch state through one top-down scan and makes other guard
    checks inspect each parent-child edge once, preserving if false and #if 0
    behavior.
  • On the synthetic 800-branch header, direct CodeParser.parse_bytes time fell
    from 108.417 seconds (baseline) to 0.231 seconds (patch) on macOS 15.8
    arm64/Python 3.13.9. This timing does not cover a full CLI build.

How it was tested

  • uv run pytest tests/ --tb=short -q — 4269 passed, 850 skipped, 2 xfailed,
    2 xpassed; one Starlette deprecation warning. A temporary 20 ms
    PollingObserver shim avoided an unrelated macOS FSEvents crash; no project
    file was changed for the shim.
  • uv run ruff check code_review_graph/ — passed.
  • uv run ruff check code_review_graph/ tests/test_cpp_qt_headers.py — passed.
  • uv run pytest tests/test_cpp_qt_headers.py --tb=short -q — 15 passed.
  • uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
    reported one type error at code_review_graph/embeddings.py:253, outside this
    PR's changed files.

Checklist

  • Tests added for new functionality
  • All tests pass: uv run pytest tests/ --tb=short -q
  • Linting passes: uv run ruff check code_review_graph/
  • Type checking passes:
    uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
  • Lines are at most 100 characters
  • Docs updated where behavior changed (README, docs/, docstrings)

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

1 participant