refactor: dedup the reentrant-mutation guard message - #21
Merged
Conversation
The identical 'reentrant mutation on the same RangeSet is not allowed' RuntimeError text was repeated at all five reentrancy-guard sites (the four collapsed authoritative add/discard/release/reserve hot paths and the allocate guard). Hoist it to a module constant. The message is only constructed on the error path, so the hot path is unaffected. Left intentionally as-is after review: the per-op lock+reentrancy-guard scaffolding (inlined for the measured hot-path win; a context manager or helper re-adds the call overhead just removed) and the self-contained per-experiment evidence verifiers (distinct schemas/gates; tamper-resistant by design).
Merged
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.
Summary
Code cleanup / style / deduplication pass over the perf work landed in #19 and #20.
After a full audit of the session's additions, the only safe, no-coupling, no-perf-impact duplication worth removing was the reentrant-mutation guard message, repeated verbatim at all five reentrancy-guard sites. It is now a single module constant
_REENTRANT_MUTATION_MESSAGE. The message is built only on the error path, so the hot path is unchanged (scalar unsynchronized still ~4.6–5.0 M ops/s).Deliberately left as-is (with rationale)
The audit found that most apparent duplication is intentional and justified; consolidating it would add cost or risk for no real benefit:
add/discard/release/reserveauthoritative paths). Factoring it into a context manager re-introduces thewith__enter__/__exit__calls that perf: fast native RangeSet mutation with selectable locking #20 measured as the dominant per-op cost; a plain helper or decorator adds an equivalent call frame. The duplication is the measured price of the ~5 M ops/s scalar path and is documented in the code._gate,_provenance,verify_artifacts,render_markdown,_git_metadata,run_matrix— each with a distinct implementation per file). These encode each experiment's own schema, gates, and provenance and are intentionally self-contained for tamper resistance._percentile,_checksum,_reject_*,_bootstrap). Only_percentileis byte-identical, and its four copies live in three different packages (tests/performance/experiments/,tests/performance/, andscripts/). Extracting it would couple a standalone CI verifier script to the tests package — worse than an eight-line pure function. The remaining variants differ in error-message text that tamper tests match on, so unifying them risks those tests for no shipped-code benefit.Validation
mypy treemendousclean;git diff --checkclean.