Repository navigation
Count the stripper's whole-buffer work instead of timing it - #11735
Conversation
test_early_markup_is_not_slower_than_the_code_it_replaces compared CPU time against the reference strip with a 10% margin. With markup at the front and nothing settled the two arms do the same strip, so the ratio sits at 1.0 and runner noise alone spans 0.89 to 1.09; it failed on #11724, which does not touch the stripper, at 0.444s against 0.404s. The regression it guards, paying the whole-buffer checks on every token, measured 1.11 to 1.33, so no margin separates it from the noise. Count the work instead: no token pays _needs_whole_buffer, and _full_strip reads no more text than the reference. A second case puts the markup at offset 0, which reaches the degenerate branch the timed version never exercised.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e94839cc55
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def counting_full_strip(self, text): | ||
| stripped_chars.append(len(text)) | ||
| return full_strip(self, text) |
There was a problem hiding this comment.
Count the scans performed inside
_full_strip
When a regression adds or reintroduces a whole-buffer pass inside _full_strip, this wrapper still records only one len(text) and the assertion below remains equal to reference_chars, even if the implementation scans that text repeatedly or becomes quadratic. Because this commit removes the runtime comparison, it no longer protects the test's stated performance guarantee; instrument the underlying passes or otherwise measure the actual work rather than only the size of each _full_strip argument.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. Counting only the size of _full_strip's argument could not see a second pass inside it. Fixed in 50088b8: the test now counts the characters each arm hands to strip_outside_think and strip_segment (both arms reach them through the same module objects), plus the blocked-body masking only the incremental arm runs, and holds the incremental arm to the reference's totals. Duplicating the strip_outside_think call or the masking call inside _full_strip now fails both cases with the doubled count (11446500 against 5723250). A slowdown inside strip_segment itself costs both arms the same, so the timed version could not catch that either.
Counting only _full_strip's argument could not see a second strip or scan inside it. Count the characters each arm hands to strip_outside_think and strip_segment, and to the blocked-body masking, and hold the incremental arm to the reference's totals. A doubled strip_outside_think or masking pass now fails with the counts that grew.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…i#11735) * Count the stripper's whole-buffer work instead of timing it test_early_markup_is_not_slower_than_the_code_it_replaces compared CPU time against the reference strip with a 10% margin. With markup at the front and nothing settled the two arms do the same strip, so the ratio sits at 1.0 and runner noise alone spans 0.89 to 1.09; it failed on unslothai#11724, which does not touch the stripper, at 0.444s against 0.404s. The regression it guards, paying the whole-buffer checks on every token, measured 1.11 to 1.33, so no margin separates it from the noise. Count the work instead: no token pays _needs_whole_buffer, and _full_strip reads no more text than the reference. A second case puts the markup at offset 0, which reaches the degenerate branch the timed version never exercised. * Count the passes inside the strip, in both arms Counting only _full_strip's argument could not see a second strip or scan inside it. Count the characters each arm hands to strip_outside_think and strip_segment, and to the blocked-body masking, and hold the incremental arm to the reference's totals. A doubled strip_outside_think or masking pass now fails with the counts that grew.
Summary
(Python 3.13, a-k)failed on #11724, which does not touch the stripper:The test compared the CPU time of
StreamingMarkupStripper.stripagainst the reference full strip with a 10% margin. With markup at the front and nothing settled, the two arms do the same strip, so the ratio sits at 1.0 by design.Measured on an idle machine, best of 3 per trial:
The healthy runs reach 1.09 and the regressed runs start at 1.11, so no timing margin reliably tells them apart. The product is fine and the test cannot make the distinction it was written for.
Change
The work is countable, so the test now counts it instead of timing it:
_needs_whole_bufferis called on no token._full_stripreads no more characters than the reference (on main it is exactly equal)._reference_strip, and a check that_full_stripran on every token keeps the counters from being vacuous.A second case puts the markup at offset 0. That reaches the degenerate branch and its
self._floor andguard, which the timed version never exercised.Testing
studio/backend/tests/test_streaming_stripper.py: 67 passed.(cut or self._floor) andandself._floor and: both cases fail, with 1500 of 1500 tokens paying the checks.self._floor and:[at-offset-0]fails (1486 tokens) and[near-front]passes. The old timed test measured 0.94 to 1.08 there and could not see it.