Repository navigation
ci: perf guard lint keeps the #1303 code shapes (Fixes #1429) - #1430
Merged
Merged
Conversation
…(Refs obs-rust#1429) RED: ci/test_perf_guard_lint.py against a stub that finds nothing. 11 of 15 fail (10 failures, 1 error); the 4 that pass check that a guarded shape passes, which the stub does trivially. The lint reads ci/perf-guards.toml. Each guard names a file, a Rust function, the attributes and code shapes that must stay, shapes that must not come back, the reason and the bench to run. The function must also carry a `PERF GUARD #<issue>` comment, so a reader (or an LLM) sees the warning before the lint fires. Comments do not satisfy a required shape, whitespace does not matter, and a guarded function that is gone fails. uv run python -m unittest discover -s ci -p test_perf_guard_lint.py Co-Authored-By: Claude Opus 5.5 <[email protected]>
…st#1429) GREEN: 15/15 ci/test_perf_guard_lint.py, and the repo's guards hold (`perf_guard_lint: 4 guards hold`). Runs in the lint lane next to ci/platform_ifdef_ratchet.py. ci/perf-guards.toml has four guards for the obs-rust#1303 AV1 keyframe walk: parse_obu_header keeps its two constant-start calls and #[inline(always)] and does not get `1 + usize::from(` back; obu_after keeps #[inline(always)]; keyframe keeps #[inline]; leb128 keeps `shift += 7` and does not get `i * 7` back. Each reason states what was measured. The guarded functions in av1.rs carry a `// PERF GUARD obs-rust#1303 (ci/perf-guards.toml)` comment. With av1.rs put back to its shape before obs-rust#1303, the lint reports 11 problems, for example: rust/obs-codec/src/av1.rs: fn parse_obu_header has `1 + usize::from(` again perf guard obs-rust#1303: two calls with a constant start make LLVM keep a branch; a computed start (1 + extension_flag) becomes a select, ... measure first: soldr cargo bench -p obs-c-oracle --bench port_comparison -- av1/keyframe (x86_64 Linux, against GCC) then change the guard in ci/perf-guards.toml together with the code Also: 85/85 obs-tests-codec, clippy -D warnings, rustfmt, test_local_gate and test_ci_tests_stdlib_only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees
approved these changes
Oct 18, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
Coordinator review: LGTM. This is the hardening asked for on #1303.
- Each guard names its issue, the reason with measured numbers, and the bench to re-run, so a failing lint tells the next person (or LLM) what to measure, not just what not to touch.
- Comments are stripped and whitespace ignored before matching, so rustfmt and doc edits don't trip it; a guard whose function is gone fails, so it can't silently rot.
- Wired into the lint lane next to
platform_ifdef_ratchet, with its own tests inci/test_perf_guard_lint.py.
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.
Fixes #1429 (follow-up to #1303 / #1426).
Why
#1426 is fast because of how LLVM translates one shape of code: two calls with a constant start keep a branch in the AV1 OBU walk. The "simpler"
1 + extension_flagbrings back a select and 1.6x the C code on x86_64 Linux, and no test fails, because the behaviour is the same. On #1303 you asked for hardening through comments and custom linting, as a deterrent for future LLMs. This is that lint.What
ci/perf-guards.toml: the guards. Each one names a file and a Rust function,attributes(must be right above thefn),require(must be in the body),forbid(must not be in the body), thereasonwith the measured numbers, and thebenchto run.ci/perf_guard_lint.py: checks the guards. It runs in the lint lane (ci/local_gate.py, next toplatform_ifdef_ratchet). Stdlib only, Python 3.11+ (tomllib).rust/obs-codec/src/av1.rs: a// PERF GUARD #1303 (ci/perf-guards.toml)comment on each guarded function, so the warning is in the code before the lint fires. The lint also fails if the comment goes.Rules: a required shape in a comment does not count, whitespace does not matter (rustfmt), and a guarded function that is gone fails. To change guarded code: measure, and change the guard in the same PR with the numbers.
First guards, all from #1303:
parse_obu_headerobu_after(buf, 1),obu_after(buf, 2),#[inline(always)]1 + usize::from(obu_after#[inline(always)]keyframe#[inline]leb128shift += 7i * 7What it prints
With
av1.rsput back to its shape before #1426, the lint reports 11 problems. The reason and the bench come once per guard:Design choice
Python next to the ifdef ratchet, not a Dylint. The checks are textual ("this call stays", "this attribute stays"), and a Dylint needs
rustc_privateand a pinned nightly for this. If you prefer a Dylint, I can port it.Tests
ci/test_perf_guard_lint.pyagainst a stub that finds nothing: 10 failures, 1 error of 15. The 4 that pass check that a guarded shape passes, which the stub does trivially.uv run ci/perf_guard_lint.pyon master:4 guards hold.test_local_gate,test_ci_tests_stdlib_onlyOK. 85/85obs-tests-codec, clippy-D warnings, rustfmt (theav1.rschange is comments only).🤖 Generated with Claude Code