Skip to content

perf: prefilter behavior shortcuts for larger catalogs - #101

Open
yeahjack wants to merge 6 commits into
vladelaina:mainfrom
yeahjack:perf/shortcut-filter-20261005
Open

yeahjack wants to merge 6 commits into
vladelaina:mainfrom
yeahjack:perf/shortcut-filter-20261005

Conversation

@yeahjack

@yeahjack yeahjack commented Oct 5, 2026 •

Copy link
Copy Markdown

Summary

Prefilter behavior shortcuts with the existing pure press/release matchers when the active catalog has at least 32 behaviors. Unrelated inputs avoid scanning behavior IDs. Smaller catalogs retain ID-first matching because parsing stale bindings can cost more than a short scan.

The production optimization is now only 8 added lines. The original inner ID-first matching/action body and following code remain verbatim; actual large-catalog hits intentionally recheck the pure matchers. Binding/catalog order, global priority, repeated downs, releases, expression selection and Alt+1…0 fallback are unchanged. No cache, allocation or persistent state is added.

Independent base: 4283de1599c7da914138f82a99405d67c2c861ec. This refresh contains only this optimization, its validation and the small build cleanups below; it does not restore functionality removed upstream or depend on another optimization PR.

Verification

  • Full Linux Release diagnostic build with warnings as errors; all 6 CTests pass
  • 16,590 ordered external-action and complete-app-state comparisons against a frozen copy of current upstream, verified byte-for-byte apart from test symbol remapping
  • Explicit expected action traces and seeded differential sequences cover the 31/32/33 boundary, duplicate/stale/empty IDs, failures, priorities, releases, repeated downs, all Alt digits, gamepad thresholds and malformed shortcuts
  • Focused ASan/UBSan passed; source line policy and diff whitespace checks passed
  • The acceptance contract was frozen before gap-closing changes: Acceptance spec and traceability map SC-01…09 to code, tests and limits
  • Spec-driven tests cover an uninterrupted held-input stream through 31↔32↔33, zero/regrowth, in-place binding/catalog edits and fallback; every timed fixture now passes ordered-trace/full-state parity preflight
  • Independent review checked final production semantics, test-oracle provenance, assembly, build flags and every published statistic; injected POSIX clock failure exits clearly without measurement rows

Fresh measurements on this base

GCC 14.2, Release -Os plus IPO/LTO, Xeon Platinum 8573C shared Linux cloud host. Old/new implementations use the same executable, compiler settings and validator-checked fixtures. Three runs each contain three warmup pairs and 31 alternating measured pairs per scenario. Other project builds/tests were paused; no exclusive CPU or affinity isolation is claimed.

Medians of the three run-level wall medians:

Scenario Before After Median speedup range
128 behaviors, 8 mixed bindings 5.820 µs/event 1.476 µs/event 3.87–7.04×
128 behaviors, 128 unmatched bindings 87.684 µs/event 9.364 µs/event 9.30–10.52×
128 label overrides, 8 active shortcuts 89.555 µs/event 1.793 µs/event 41.32–85.86×

The first cached-match version caused an avoidable stale-31 regression. GCC/LTO inspection showed loop indices spilling to memory while match booleans occupied registers. The simpler guard restores both loop indices to registers. In three contemporaneous cached/guard comparisons, stale-31 changed from 0.884–0.943× to 1.094–1.687×, without tuning the threshold or fixtures. This supports removing the structural cost; noisy timings do not establish its precise causal magnitude.

Residual costs remain: one behavior with 64 stale bindings costs 6.60–37.01 ns/event more (0.9–7.2%) in these runs. The guard adds a decision per binding and the measured dispatcher stack reservation is 72 bytes versus baseline 56 (rejected cached version: 88); these are compiler-specific benchmark observations, not application memory claims. The threshold is an empirical tradeoff, not a universal speedup guarantee. Run 2 has substantial shared-host variation, so upper speedup ranges should not be treated as stable device performance.

All 78 scenario/run summaries and 2,418 final guard-only raw paired samples, wall/process-CPU measurements and reproduction commands are in tests/runtime/README-shortcuts.md and its linked CSV files. These are dispatch component costs with deterministic external-action doubles. Batch-average p95 values do not establish individual-event tails, whole-app CPU, FPS or input-to-frame latency. Bounded calibration and shared-host noise limit small-difference conclusions. No previous-base measurements are reused.

Build compatibility and scope

Two small fixes for warnings inherited from the current baseline are kept separate from the optimization: split two independent audit if statements onto separate lines, and compile remove_receipt under the same BONGO_CAT_HAS_CUBISM condition as its existing caller. The helper body and call path are unchanged. No warning exemptions are required.

Linux diagnostic-backend coverage does not establish native Windows/macOS behavior, licensed Cubism rendering, GPU/window correctness or input-to-photon latency. LeakSanitizer is unavailable under this executor's tracing; leak checking is not claimed.

Current-head review and CI status

Published head: 758fa1294b2b169c8b8455ada637d45e86c802e2; tested tree: 63c6bb13e6de74ea1236d12ffd974c6d10202c69. The tree was verified against the tested local source after a protected, expected-old-head ref update. GitHub reports no merge conflict and the PR is Ready for review. No merge, auto-merge or deployment was performed.

CI has not passed: the current-head workflow run completed as action_required, with zero executed jobs and zero check runs. A repository maintainer must approve the workflow before cross-platform jobs can run. The fork has no run for this head. Local strict builds and focused tests are the established evidence; Ready for review is not a ready-to-merge claim.

@yeahjack
yeahjack marked this pull request as ready for review October 5, 2026 14:33
@yeahjack
yeahjack force-pushed the perf/shortcut-filter-20261005 branch from 8301d93 to 758fa12 Compare October 5, 2026 16:28
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.

1 participant