fix(tools): stop masking a function body window once its brace closes #9966
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9966"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T00:37:41Z.
What
conventions_function_bodies_shard_11got about ten times slower oncetest_large_export_set_checks_duplicates_without_command_line_limitlanded (a24a5524b, via #9137). Since then it is the slowest conventions shard on every runner, and it has already hit the 30 s CTest timeout onrelinker (windows-latest, g++):Before that test, shard_11 had a median of about 1.4 s in the same jobs.
The time is not in the duplicate check itself, so comparing libraries first (
928588bbb) does not help:code()still callsfunction_body()once for every added export line.function_body()masks a fixed 400-line window withcpp_text()for every export it looks at, even when the body closes on the same line. With 2000 exports in one file,cProfileshows 2001function_bodycalls, 8.7 M calls to the mask callback and about 95% of the test's time.function_body()now goes through theCPP_TOKEN.finditer()matches of the same window lazily and stops at the brace that closes the body.re.subbuilds its result from the unmatched gaps and the masked matches in order, so the masked text up to that brace is the same as before. It still returnsNonewhen a;comes before the first{, when there is no{, and when the body does not close inside the window. The mask callback is moved out ofcpp_text()ascpp_mask()so both use it.cpp_text()itself still usesre.suband gives the same output.Tested
Linux x86_64 (Ubuntu 26.04, Ryzen, Python 3.14), main
6ef5a1c4c, before the rebase:conventions_function_bodies_shard_11on its own: 6.60 s before, 0.49 s after. Other shards: 0.2-0.7 s, about the same.test_check_conventions_comments.py --shard 11/12pinned to one core, withtimeout 30: main 6/6 killed at 30 s, this branch 6/6 pass in 3.0 s.ctest -R "^conventions": 24/24.function_body()against every tracked C/C++ source (2889 files, about 252k calls). The inputs were lines with{orAPS5plus random lines, both raw and already masked: 0 differences. The old version took 309 s and the new one 48 s.cpp_text()output was the same for every file, with and withoutpreserve_comments.tools/check_conventions.py --base origin/main~300: byte-identical output with the old and new checker.macOS arm64 (M2 Max), rebased on main
83462cc57:--shard 11/12: 6.90 s before, 2.20 s after with/usr/bin/python33.9.6; 6.27 s before, 1.75 s after with Python 3.14.7.test_large_export_set_checks_duplicates_without_command_line_limitalone: 5.58 s before, 0.54 s after.tools/tests/test_check_conventions_*.pyfiles pass with both Pythons.function_body()andcpp_text()against every tracked C/C++ source (2930 files, about 92k calls on raw and masked lines): 0 differences.tools/check_conventions.py --base origin/main~300 --head origin/mainand--base origin/main~1000: byte-identical output with the old and new checker (140 findings, 33 errors on the larger range).python3 tools/check_conventions.py --base origin/mainpasses.The other open PRs that touch
tools/check_conventions.py(#9660, #9855) merge that file cleanly with this branch.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:52:49Z.
Review: CHANGES_REQUESTED
The hosted Conventions check fails the required PR-template section check: the body uses
## Summaryand## Testing, while the repository template and checker require### Whatand### Tested. The check-run annotations identify all three required sections as missing, so the PR remains blocked even though local source conventions pass.Please rename those two headings to the template headings and keep the checklist section. I reviewed the
function_bodychange: it masks tokens lazily and stops after the matching closing brace, preserving the previous return conditions; the reported differential tests are relevant. The relinker matrix passes, while the native build jobs are skipped. I did not run the full test suite locally.Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-25T00:09:38Z.
Review: APPROVED
Reviewed
db01701db5798550dc895a904ca7ecc34d6eaca4against83462cc57ddecac5e5f3cdafafbe38d406e55953. No actionable findings in this focused review.Source review: Inspected the complete parser optimization. Lazy token pieces retain unmatched text and the same comment/string masking, stop at the first completed function body, and preserve the semicolon-before-opening-brace and 400-line limits. The shared mask retains cpp_text's preserve_comments behavior.
Validation: Windows Python 3.11:
tools/tests/test_check_conventions_comments.py -v, 79 passed, 0 skipped on both head and baseline. An independent deterministic comparison found no differences for 1,500 inputs in either masking mode or function-body extraction, plus 500 one-line functions. On that bounded same-process fixture, baseline took 0.491 s and head 0.006 s, baseline first; this is a synthetic measurement, not a general throughput guarantee. Conventions, whitespace and script registration passed. Current hosted relinker matrix, ASan and latest conventions succeeded; full-product jobs were skipped.Scope: Python parser behavior and bounded local timing. No application/game performance claim is made.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T01:29:39Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested for current-main integration and title
The checker optimization’s focused tests pass on this head, but the branch predates substantial edits to the same file on current
main, and theperftitle still triggers the repository’s missing-performance-data rule.What I ran
db01701db5798550dc895a904ca7ecc34d6eaca4against currentmain3a2b91981651569163768854a1fcdc7193b6667b.python3 tools/tests/test_check_conventions_comments.py -v.python3 tools/check_conventions.py --base upstream/main --head HEAD.git diff --check upstream/main...HEAD.git merge-tree --write-tree upstream/main HEAD.python3 tools/pr_overlap.py --branch refs/remotes/review/9966.Results
test_check_conventions_comments.pymainbd386af5cfac17cbea756ba67975eea96638ae4fRaw output excerpts
Negative control
Not run. The focused test suite passes, but a baseline comparison was not part of this review.
Findings
Blocking
Update onto current
mainand rerun. The branch is based on83462cc57ddecac5e5f3cdafafbe38d406e55953, 6,729 commits behind currentmain. Since that base,tools/check_conventions.pychanged by 172 lines, including its template and export checks. The merge preview is clean, but the modified parser needs testing with those current checks in the same tree.Resolve the
perftitle/report mismatch. The PR body says there is no title, scene, or application trace for this tools-only speedup. The repository labelsperf(...)PRs as requiring a pair of validaps5-summary.jsonllines and trace evidence. As you offered in the thread, please retitle this asfix(tools)ortest(tools)if the change is not intended to make a traced application-performance claim.Non-blocking
tools/check_conventions.py. I independently ranpr_overlap.pyand a merge preview of the exact heads; neither reports a conflicting change, so I found no basis to require a dependency at this time.Sources
mainversion of the checkerNot verified
main.To get this to a good state
Rebase or otherwise update the branch to current
main, rerun the 79 focused tests and conventions check on that combined head, and retitle it away fromperfif it does not provide the required application traces. I will recheck the resulting head and report.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T02:31:20Z.
Review: APPROVED
Re-checked — new head, looks good
I re-reviewed exact head
1c968013edagainst current main3a2b919816; the merge preview is clean, all 82 focused conventions tests pass, and the large-export regression test is about 19.8 times faster here.What I ran
Environment: Linux x86_64, kernel 6.1.0-54-amd64, Python 3.11.2. I used isolated worktrees for the PR head and current main.
The last command ran once in the PR worktree at
1c968013edand once in the base worktree at3a2b919816.Results
Raw output
Negative control
Findings
Blocking
None found.
Non-blocking
The two hosted macOS relinker jobs are queued; I have not counted them as passes. The exact-head unit tests, Windows and Ubuntu relinker jobs, merge preview, and conventions check all passed.
Sources
Not verified
I did not run the full project build, project-wide CTest suite, or console behavior. The hosted macOS relinker jobs remain queued; Linux and Windows project-wide jobs are marked skipped.
To get this to a good state
No code change is needed for the reviewed head. Let the queued macOS jobs finish; if the head changes, I will rerun these same checks and the large-export comparison on the new revision.