Skip to content

perf(tbr): finish T-300 — incremental rescore for TBR-rerooting accepts - #47

Open
ms609 wants to merge 1 commit into
cpp-searchfrom
claude/treesearch-issue-38-8103cc
Open

perf(tbr): finish T-300 — incremental rescore for TBR-rerooting accepts#47
ms609 wants to merge 1 commit into
cpp-searchfrom
claude/treesearch-issue-38-8103cc

Conversation

@ms609

@ms609 ms609 commented Aug 4, 2026

Copy link
Copy Markdown

Fixes #38

What was actually left

Most of #38 was already done. T-300 landed its SPR half long ago (f531bbcd EW, 014ccdea NA), so the issue text — and its line numbers (ts_tbr.cpp:1134) — describe code that no longer exists. The residue was accepts that rerooted the clipped fragment: those still fell through to full_rescore.

apply_tbr_move reverses the parent/child links along clip_node..reroot_parent, so every node on that path gains new children — and after the reversal that path is clip_nodes rootward chain. One extra dirty seed at clip_node therefore covers the rerooting case exactly, with no new machinery: the NA kernel already took a third seed for precisely this region (it backs exact_verify_sweep), so this adds the same parameter to the EW/IW kernel and drops the is_spr gate at the accept site.

Read this before merging: the lever is spent

dataset × mode accept branch, % of tbr_search wall
Vinther2008 EW / IW 0.51 % / 0.43 %
Agnarsson2004 EW / IW 0.18 % / 0.22 %
Zanol2014 EW 0.22 %

Post-T-300 the whole accept branch is 0.18–0.51 % of tbr_search wall (in-DLL na_t_accept_ms, 15 paired cells, arms interleaved because the box is shared). This patch cuts that slice to ×0.901 median (faster in 12/15 cells)≈0.03 % end-to-end — undetectable.

Rerooting accepts are ~18 % of accepts, so that ceiling is real, not thin coverage. The case for merging is codepath unification, not speed — one fewer special case, and the accept path now shares its dirty region with exact_verify_sweep. If you would rather not touch a correctness-critical hot path for no measurable gain, closing this unmerged is a reasonable call; the measurement is the durable part and is recorded either way.

dev/profiling/findings.md and focus-areas.md now mark area 4 AT-LIMIT, and flag that the T-300 rows "19.2 % of NA-path DLL CPU" is the pre-fix number so it is not re-read as a live target.

Correctness

An earlier incremental attempt shipped a systematic delta = -3 (b7303ee5), so this is evidenced rather than argued:

  • TS_TBR_ACCEPTCHK — new env-gated in-flight oracle: cross-checks every incremental accept against full_rescore and aborts on drift. Clean over a 70-cell battery (1322 accepts) and over 624 assertions spanning the constrained, pool, IW, XPIWE, sector and drift paths.
  • Byte-identical trajectories — scores and accept counts match the pre-patch library in all 15 A/B cells and all 70 battery cells.
  • Non-vacuous regression test — the four existing tests assert score identity but cannot tell whether the rerooting arm was ever entered, so they would pass just as happily if it were dead. n_reroot_accepts (src/ts_data.h) is asserted positive for each of EW / IW / NA / NA-IW, so losing coverage fails the test instead of silently voiding it.

CI

ubuntu-arm64 green (full R CMD check). windows fails, and it fails identically on cpp-search — I dispatched a control run (30909722952) to check rather than assume: same job, same step (Set up R dependencies, Cant find package called MaxMin), R CMD check skipped. Pre-existing infrastructure breakage, nothing to do with this branch.

🤖 Generated with Claude Code

T-300's SPR half landed long ago (f531bbc EW, 014ccde NA); what issue #38
still describes as "full_rescore after every accepted move" is now only the
residue: accepts that rerooted the clipped fragment, which still fell through
to full_rescore.

apply_tbr_move reverses the parent/child links along clip_node..reroot_parent,
so every node on that path gains new children — and after the reversal that
path IS clip_node's rootward chain. One extra dirty seed at clip_node
therefore covers the rerooting case exactly, with no new machinery: the NA
kernel already took a third seed for precisely this region (it backs
exact_verify_sweep), so this only adds the same parameter to the EW/IW kernel
and drops the is_spr gate at the accept site.

Measured, and the honest answer is that the lever is spent. Post-T-300 the
whole accept branch is 0.18-0.51% of tbr_search wall (in-DLL na_t_accept_ms,
Vinther2008/Agnarsson2004/Zanol2014 x EW,IW, 15 paired cells). This cuts that
slice to x0.901 median (12/15 cells) => ~0.03% end-to-end, i.e. undetectable.
Rerooting accepts are ~18% of accepts, so that is a real ceiling, not thin
coverage. The case for merging is codepath unification, not speed; area 4 is
recorded AT-LIMIT so it is not profiled again.

Correctness, given an earlier incremental attempt shipped a systematic
delta=-3 (b7303ee):
  - TS_TBR_ACCEPTCHK, a new env-gated in-flight oracle, cross-checks every
    incremental accept against full_rescore and aborts on drift. Clean over
    the 70-cell battery (1322 accepts) and over 624 assertions spanning the
    constrained, pool, IW, XPIWE, sector and drift paths.
  - Scores and accept counts are byte-identical to the pre-patch library
    across all 15 A/B cells and the 70-cell battery, so trajectories are
    unchanged.
  - n_reroot_accepts (src/ts_data.h) makes the new regression test
    non-vacuous: the four pre-existing tests assert score identity but cannot
    tell whether the rerooting arm was ever entered, so the new one asserts
    coverage as well as correctness.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ms609

ms609 commented Aug 4, 2026

Copy link
Copy Markdown
Author

🟢 on /code-review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lazy apply_tbr_move rescore in tbr_search

1 participant