Skip to content

perf(tests): parse the source trees once per worker #4700

Closed
1 of 1 issue completed
Closed

Description

@dan-petty

Problem or Motivation

12 test files call rglob('*.py') and raw ast.parse. They do not use the cache of tests/support/trees.py:53-61 or the session fixture parsed_source_trees (tests/support/trees.py:91-94).

test_every_import_of_a_roadmap_module_names_a_module_that_exists (tests/invariants/test_source_tree.py:548-557) parses 2,127 files and takes 10.65 s in CI (measured). mypy proves the imports of src, and a broken import in a test fails when that test runs.

Saving: 20-30 s of CI worker time (estimated).

Found by the CI and test audit of 2026-11-11. The account runs at most 20 hosted jobs at one time (measured), so each job that does no work makes the queue of each pull request longer.

Proposed Solution & Architectural Design

  • Route the 12 files through parse_python_file or parsed_source_trees.
  • Delete the import-check test, because mypy and the test run already prove the same thing.

Risk: Low.

Target Subsystem

SDLC, Git & PR Governance (tests/invariants/, tests/telemetry/test_telemetry_instruments.py, tests/support/trees.py).

Existing Tool Considered

The existing parse cache of tests/support/trees.py and mypy. No new tool. Cost: about 20,000 tokens and 1 hour.

Acceptance Criteria

  • No test file outside tests/support calls ast.parse on an rglob result (git grep).
  • The 4 heaviest files run in 15 s or less with -n 4 and no coverage (from 26.5 s, measured).

Dependencies

None.

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    source/agent
    type/infra
    scope/tests
    status/new
    value/medium
    effort/low
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/infra. The perf prefix of the title gives the type.
    • Scope: scope/tests. The (tests) scope of the title gives the scope.
    • Priority: P2-Medium. Saves 20-30 s of CI worker time per run but does not block delivery or fix a defect.
    • Value: Medium. Reduces CI queue time for all pull requests by 20-30 s per job.
    • Effort: Low. The body estimates about 1 hour and 20,000 tokens to route 12 files through an existing cache.
    • Related: perf(tests): the invariant tests share one parse of the source tree #1749, which asks for a different change. Both share the goal of reusing one parse of the source tree in tests, but the candidate extends the fix to 12 files across invariants and telemetry and adds a test deletion.
  3. added
    priority/p2-medium
    owner/agent
    status/in-progress
    and removed
    status/new
    on Nov 11, 2026
  4. removed
    status/in-progress
    owner/agent
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-11 23:31 UTC

  6. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Acceptance criterion 2: measurement after the merge

    Command: uv run pytest -n 4 -p no:cov -q --durations=20 tests/invariants/test_source_tree.py tests/telemetry/test_telemetry_instruments.py tests/invariants/test_hermetic_floor.py tests/invariants/test_architectural_invariants.py. The time is the pytest passed in value.

    On 2026-11-12, in the devcontainer, with a load average of 34 to 44 on 16 CPUs. "Before" is 66c9ef5a (the parent of the merge), "after" is 7a163a72 (the merge of #4850). The runs alternate in ABBA order.

    Run Tree pytest time CPU (user + sys)
    1 before 543.9 s 1,135.8 s
    2 after 376.8 s 850.4 s
    3 after 331.3 s 699.4 s
    4 before 468.9 s 916.2 s

    The mean goes from 506.4 s to 354.0 s (ratio 0.699). The CPU time goes from 1,026.0 s to 774.9 s (ratio 0.755). The builder of #4850 measured the ratio 0.719 (229.0 s to 164.6 s). With these ratios, the baseline of 26.5 s becomes 18.5 s to 20.0 s. That is more than the target of 15 s. The host was loaded, so the absolute values are not valid; only the ratio is.

    No quiet host was available, and the CI logs give no time for each test file. So this comment cannot prove the absolute value. The ratio shows that the criterion "15 s or less" is not met. The costs that stay are in #4890, which is a sub-issue of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/testssource/agenttype/infravalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions