Skip to content

perf(python): reuse the source-fact parse for the foreign index's attribute writes (#10914) - #10929

Merged
EffortlessSteven merged 3 commits into
mainfrom
claude/project-thread-w6b15g
Oct 28, 2026
Merged

EffortlessSteven merged 3 commits into
mainfrom
claude/project-thread-w6b15g

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

  • The Python foreign-write index (ForeignIndex, Python ForeignWrites::scan reparses the whole workspace once per changed Python file #10125) parsed every workspace file a second time to list the attributes it assigns.
    • On pandas ecdb4258 that second parse was 3.4 CPU-s, the largest part of the index.
    • The source-fact pass parses the same files with the same parser and nesting budget.
  • The source-fact pass now records assigned_attributes, and the index reads them.
    • The names come from the original source, also for test files whose helpers it inlines, because the index reads files as written.
    • The index parses only files the fact pass did not see; the test-only build keeps parsing everything.

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge, dependency, or repo-ops development for ripr-swarm
  • repair or follow-up for a same-repo swarm PR
  • swarm-only CI, runner, routing, source-of-truth, or agent-operating surface
  • other swarm-scoped work:

Source-of-truth Links

Proposal: n/a
Spec: n/a
ADR: n/a
Plan item: Python scale / real-repo DX
Governing issue or accepted claim: #10914
Acceptance delta (one sentence): The Python foreign index takes each file's assigned attributes from the source-fact parse instead of parsing the workspace again, with byte-identical findings on the pandas and Django pins.

Candidate Relationships

Candidate branch (GitHub PR head is authoritative after publication): claude/project-thread-w6b15g
Stack parent or prerequisite PR (if any): none
Proposed replacement of PR (if any; not yet accepted): none
Acceptance retained from a replaced candidate (if any): none
Accepted winner and losing candidate disposition (when decided): n/a

Scope

  • source_facts.rs: new PythonSourceFacts.assigned_attributes.
    • Set after a successful parse.
    • Carried over from the original parse when a test file's helpers are inlined.
    • None on a parse failure, exactly as assigned_attributes(source) returns.
  • module_value.rs:
    • ForeignIndex::build_with_assigned reads the map;
    • scan_source falls back to parsing for files missing from it;
    • build is now test-only.
  • python.rs: the fact fold collects the map and passes it to the index.
  • module_constants.rs: assigned_attribute_names is now pub(super).

Scope Classification

  • One production behavior
  • One public contract
  • One architectural seam
  • Docs/spec/test-only evidence package
  • Other:

Production delta:

  • One fewer full parse per workspace Python file in diff mode. Findings and output are unchanged.

Evidence/support delta:

  • the_source_fact_parse_gives_the_foreign_index_the_same_attribute_writes checks a workspace with:

    • attribute writes;
    • a dict table;
    • a test file with an inlinable assertion helper;
    • a malformed file.

    excluding(own) from the shared map equals the self-parsing index for every file.

  • the_foreign_index_reads_supplied_attribute_writes_instead_of_parsing discriminates: a supplied write the text does not contain changes may_rebind, so the map is actually used.

Single acceptance criterion:

  • Byte-identical findings with one fewer workspace parse.

Non-goals:

Support-tier Impact

  • none

Policy Impact

  • none

Proof

cargo test -p ripr --lib python     # 1709 pass
cargo xtask precommit               # exit 0

Local measurement, release build, 4 cores, warm, --base HEAD~1 --mode draft:

  • The baseline is 4d54f6d with inert counters. The candidate is this change on 4d54f6d.
  • Each row is three interleaved runs per binary.
Pin Baseline This change Peak RSS Output vs main aaa12f6
pandas ecdb4258 12.3–13.4 s 11.8–12.4 s ~552 MiB both byte-identical (36 findings)
Django 5c13b5a 7.7–8.2 s 6.7–7.3 s ~370 MiB both byte-identical (17 findings)

Profile that chose this step: on pandas, the index's CPU-s were 3.4 for the second assigned-attribute parse, 1.5 for table uses, and 0.9 for the dict-literal lex, against 2.9 for the fact parse.

Result, failures, or skipped proof:

  • The timings are local and noisy (±0.5 s). Hosted qualification is pending.

Claim Boundary

  • May claim: one fewer full parse per workspace file; byte-identical output on the two pins.
  • Must not claim: the 2 s / 512 MiB targets. Both rows remain well above them.

Rollback

  • Revert the squash commit.

Spec-Test-Code Traceability

  • Spec: n/a (performance, no behavior change)
  • Tests: the two new tests in python/module_value_tests.rs
  • Code: ForeignIndex::build_with_assigned, extract_source_facts
  • Golden outputs: unchanged
  • Metrics: n/a
  • ADR/learning: n/a

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.
  • Unknowns include stop reasons where applicable.

CI Economics

n/a

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented in production code.
  • No new panic, unwrap, expect, todo, or unimplemented in tests.
  • New non-Rust programming files are allowlisted with owner, surface, and reason.
  • New generated, dependency, process-spawn, or network surfaces are allowlisted with owner and reason.
  • Errors are reported with actionable context.
  • Public JSON/schema changes are documented.

Gates

  • cargo fmt --check and the policy gates (via cargo xtask precommit)
  • cargo test -p ripr --lib python

Generated by Claude Code

…ribute writes (#10914)

The workspace foreign-write index parsed every Python file a second time
to list its assigned attributes. The source-fact pass already parses each
file, so it records those names (from the original source, also for test
files whose helpers it inlines) and the index reads them, parsing only
files the fact pass did not see.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 39 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 154 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: c7c2b9dd-2f32-4f7e-8fe9-df88e7d35d7d
Commits

Reviewing files that changed from the base of the PR and between c948531 and 8568ff1.

Files selected for processing: 6
  • changelog.d/10914-python-foreign-index-shared-parse.md
  • crates/ripr/src/analysis/language/python.rs
  • crates/ripr/src/analysis/language/python/module_constants.rs
  • crates/ripr/src/analysis/language/python/module_value.rs
  • crates/ripr/src/analysis/language/python/module_value_tests.rs
  • crates/ripr/src/analysis/language/python/source_facts.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 28, 2026 11:25

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request optimizes the Python workspace foreign-write index by reading each file's assigned attributes from the source-fact parse instead of parsing every workspace file a second time, which improves performance. A review comment suggests simplifying a match statement in module_value.rs using Option::cloned and Option::unwrap_or_else to make the code more concise and idiomatic.

EffortlessSteven commented Oct 28, 2026 •

Copy link
Copy Markdown
Member Author

Independent source/currentness review at 177bf80: no blocking production defect found in this bounded review. The admitted original AST feeds the same assigned-attribute collector; parse/budget failures remain None, missing map entries retain fallback parsing, and map keys/source bytes derive from the same workspace read. The merged parametrization collection-error logic remains in collect_tests_from_statements and is not altered by the cache map. Existing prior-head findings were reconciled rather than restarting benchmarks or qualification.

Nonblocking coverage correction: module_value_tests.rs:1044–1045's test_limit uses b.RATE = 3 and check(b.RATE). helper_inline::plain_test rejects that assignment (helper_inline.rs:138–148), and helper_call rejects the nonliteral argument (271–306), so this fixture does not exercise the claimed helper-inlining branch. Please narrow that test's stated coverage or add a genuinely qualifying control in the owner's normal follow-through. This is not evidence of incorrect production behavior.

No new runtime/benchmark claim is made by this source review. Owner performance measurements retain their stated runner/input limits. Existing hosted qualification is still separate; no additional CI campaign or formal PR approval was submitted.

Reconciliation of subsequent ub-review questions (same head): module_value.rs:534–550 explicitly uses Option<&Option<Vec>>; Some(None) preserves failed-parse/dynamic behavior, while outer None alone reparses. The API therefore does distinguish these states. python.rs:1002–1012,1032–1033,1237–1244 retain the same relative PathBuf and workspace source map, without a new normalization boundary. module_constants.rs:525–532 calls the shared source_facts::parse_module_result policy (source_facts.rs:577–586); the reused collector is at665–667 and original helper facts are restored at678–680. These are source-supported answers, not new runtime or exhaustive caller coverage claims. Owner benchmark/equivalence measurements remain attributed; current hosted goldens/corpora passes are narrower evidence. The helper-test coverage limitation above remains real. Corrected the earlier plain_test line pointer to138–148; the finding is unchanged.

Successor review, 8568ff1 (tree b083ae5fe429cef2c36983f605f85c949a3b195d): complete two-file delta inspected. The fixture now uses a module-level RATE assignment and literal check(3), explicitly asserts that inlining returns Some, and checks original RATE write facts. The earlier helper-inlining coverage concern is resolved. module_value.rs:534–553's cloned/unwrap_or_else refactor preserves absent / Some(None) / Some(writes) distinctions and only lazily reparses missing entries. No blocking source/currentness finding; unaffected prior reasoning retained. Owner's 82 tests/precommit result is attributed, not a new independent execution claim.

The old 177bf80 campaign was cancelled after the head changed; its failed current-eligibility check is not a source/test regression. Existing replacement qualification40690639091 must finish for8568ff18. No additional campaign was dispatched by this reviewer.

@github-actions github-actions 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.

Confirmed findings

  • The foreign index consumes source-fact assignments and falls back to parsing only when a file is absent from the map.

Verification questions

  • Confirm the PR claims byte-identical findings on pandas and Django pins, but the available packet contains no completed hosted qualification receipt; the stated measurements are local and noisy.
  • Confirm the new tests exercise supplied-map discrimination and equality against self-parsing, but do not lock the key-domain/path normalization contract across the producer and consumer.
  • Confirm test-helper inlining preserves assignment facts from the original source rather than substituting rewritten helper-call assignments.
  • Confirm the source-fact boundary owns assignment extraction, but ForeignIndex also retains a fallback parser, duplicating parse-policy ownership and requiring map-presence semantics to stay synchronized.
  • Confirm the fallback is needed for files absent from the source-fact map, but the API does not distinguish absent from present-with-None; correctness currently depends on the producer inserting every parsed or failed file.
  • Confirm the new tests compare shared and independently parsed indexes, but the packet does not show exhaustive caller or sibling-path coverage for ForeignIndex construction outside the changed PythonAdapter route.

Refuted

  • A malformed source could be silently treated as having no assigned attributes in the shared route.; refuted because: The source-fact snapshot initializes assigned_attributes to None and assigns Some(...) only after a successful parse; scan_source preserves present Some(None) as unknown/dynamic rather than an empty set.
  • Malformed or fact-unseen files might be misclassified because the shared map uses Option values.; refuted because: Some(None) represents a failed parse and is consumed as no assigned attributes; map absence invokes assigned_attributes(source), preserving fallback parsing.
  • The production path still needs to parse files missing from the supplied map.; refuted because: scan_source intentionally falls back to assigned_attributes(source), so build_with_assigned preserves behavior for files absent from the source-fact pass.

Evidence gaps

  • The PR's byte-identical-output claim is supported by the PR body and seeded thread, but the available review packet has no completed cargo-test receipt or independent golden-output artifact.
  • Model proof intent was rejected by deterministic validation.

…branch (#10914)

The test file's helper call used a non-literal argument after an
assignment, which the inliner refuses, so the fixture never reached the
branch that restores the original source's attribute writes. The test
now calls the helper with a literal, writes the attribute at module
level, and asserts both that the file inlines and that its recorded
writes are the original's. Also takes the Option::cloned simplification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYNejJJF82dVq4XHXddgrd

Copy link
Copy Markdown
Member Author

Coverage finding repaired in 8568ff1. The test file now writes b.RATE at module level and calls check(3) with a literal, so inline_test_helpers takes the file. The test now asserts:

  • the inliner returns a rewrite for it;
  • its recorded writes are Some(["RATE"]), taken from the original source;
  • the shared index still equals the self-parsing one for every file.

The Gemini Option::cloned nit rode the same push. precommit 0; 82 module_value tests pass.


Generated by Claude Code

@github-actions github-actions 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.

Decision

  • Needs one verification check before upstream.

Verification questions

  • Confirm producer and consumer use the same relative PathBuf key, but the reviewed code does not independently lock path normalization when the workspace source iterator supplies absolute paths or alternate spellings.

Refuted

  • The map cannot distinguish absent files from files whose parse failed, causing incorrect fallback behavior.; refuted because: The map value is Option<Vec>; a missing key triggers fallback parsing, whereas a present None is retained and remains equivalent to the prior assigned_attributes result on parse failure.
  • The shared facts change the ownership boundary in a way that duplicates parse policy or requires an architectural rewrite.; refuted because: Assignment extraction remains in source_facts.rs, the index only consumes the result, and fallback parsing is retained for files not represented in the map; the change is localized and does not introduce a competing production path.
  • Supplying a map entry with None could suppress the independent parser and lose assignment information.; refuted because: None is treated as a successful source-fact result with no available assignment facts, while map absence triggers assigned_attributes(source); this matches the source-fact parse-failure contract and avoids reparsing failed files.

Evidence gaps

  • The local byte-identical pandas and Django results are not backed by a completed hosted qualification receipt, so the changelog should not be read as hosted qualification evidence.
  • Model proof intent was rejected by deterministic validation.
  • Byte-identical output on the pandas and Django pins is claimed from local measurements, but no hosted qualification receipt is available in this packet.
  • Hosted qualification is not present in the packet, so byte-identical pandas/Django output and the performance improvement are not independently established here.

Copy link
Copy Markdown
Member Author

Review of record — head 8568ff1

Disposition: nothing blocking; merging.

Correctness

  • The fact pass records assigned_attribute_names(&module.body) right after its own successful parse_module_result. That is the same parser, nesting budget and collector that assigned_attributes(source) uses, so a parse or budget failure stays None.
  • A test file whose helpers are inlined keeps the writes of the source as written, which is what the index reads.
  • In the index, a missing map entry parses as before, Some(None) stays failed/dynamic, and Some(writes) is used as is.

Key domain (verifier question)

  • Both sides use the relative PathBufs of the same workspace read: the fact pass iterates workspace_files and looks up workspace_read.sources, and the index iterates workspace_read.sources.
  • A key spelling mismatch would only fall back to a parse. It costs time, not correctness.
  • The measured drop on both pins shows the map is hit.

Tests

  • the_source_fact_parse_gives_the_foreign_index_the_same_attribute_writes checks equality of the shared and self-parsing index for every file. As of 8568ff1, the fixture also:
    • takes the helper-inlining branch, asserting that inline_test_helpers returns Some;
    • records Some(["RATE"]) for that file;
    • records None for a malformed file.
  • The independent review's coverage finding is repaired.
  • the_foreign_index_reads_supplied_attribute_writes_instead_of_parsing discriminates map use.

Perf / output (local, attributed)

  • Measured on 4d54f6d plus this change, warm, 4 cores, three interleaved runs per binary:
    • pandas ecdb4258: 12.3–13.4 s → 11.8–12.4 s;
    • Django 5c13b5a: 7.7–8.2 s → 6.7–7.3 s.
  • JSON output was byte-identical to main.
  • These are local measurements, not hosted evidence.

Proof

  • cargo xtask precommit exit 0; 1711 Python lib tests pass after merging main c948531.
  • Hosted on 8568ff1: Ripr Rust Small Result success, with gates and all 4 test shards green.
  • The failed Result on 177bf80 was that run being cancelled when the head changed.

Threads and providers

  • Gemini's Option::cloned nit was applied and its thread resolved.
  • Devin found no issues. CodeRabbit was rate-limited, so its review is missing, not clean.
  • The independent source review on 8568ff1 has no blocking finding.

Generated by Claude Code

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants