Skip to content

Use scaled log moments in prepared MEPV scans - #95

Draft
frankier wants to merge 6 commits into
codex/grid-preallocation-scratchfrom
codex/prepared-log-mepv
Draft

frankier wants to merge 6 commits into
codex/grid-preallocation-scratchfrom
codex/prepared-log-mepv

Conversation

@frankier

@frankier frankier commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Stacked on #93. Replace binary log-MEPV's separate normalization and checked moment sweeps with PBB #24, using FIB #25's prepared native log-response evaluator once per candidate.

Candidate conditioning stays in log space until each outcome has been shifted by its own maximum. Scratch explicitly stores per-outcome logs and scaled weights, preserving extreme tails and long-history behavior. At the point estimate, banks already recognized as preserving both ordinary response tails use resp_vec directly, avoiding a log/exp round trip. Custom banks and logarithmic wrappers retain the native-log fallback. Explicit inlining keeps that dispatch allocation-free; tests cover workspace reuse and floating criteria through LogItemBank.

This PR remains a draft. Root/test/docs sources pin PBB 3e23026 and FIB c2a882b; released dependencies must replace these pins before acceptance. Minimum-dependency downgrading is deferred while draft sources exist. Julia 1.12 and 1.13 still run tests; coverage uploads only from 1.13 to avoid the observed Coveralls build-close race.

Focused numerical, tail, derivative, long-history and prepared-scan tests pass on Julia 1.13.3, including zero allocations per prepared candidate. Full CI passes on the final revision 2c8103a: Julia 1.12, Julia 1.13 and documentation.

Fresh Julia 1.13.3 benchmarks

Single thread pinned to CPU 0; 33 points on [-4,4], Normal(0,1), ten fixed responses and the original CATExperiments 100-million-item RNG prefix. Warmed variants are randomly interleaved: 31 rounds through 10,000 items, 21 at 100,000. All 456 timed samples have zero compilation and GC time.

Items Linear Float64 Previous PR log control New log Float64 New log / linear¹ Speedup over control¹
1,000 0.407 ms 4.075 ms 3.675 ms 9.13× 1.105×
10,000 4.010 ms 41.225 ms 36.876 ms 9.15× 1.121×
100,000 46.670 ms 478.295 ms 431.889 ms 9.18× 1.112×

¹ Medians of paired ratios; timing columns are medians. The control reconstructs the preceding PR's candidate kernel (CAT b00f94b, FIB ad929b5) in local benchmark functions using the unchanged PBB kernel. It does not override package methods; its entry-point overhead differs slightly from Stateful.next_item. Absolute timings vary between sessions, so compare the fresh interleaved controls within this run.

At 100,000 items, the new FIB evaluator with the old point-probability calculation takes 447.160 ms. Paired speedups are 1.077× from FIB and another 1.037× from CAT's point probabilities. This step reduces log time by about 10%; the 2×-linear target remains unmet, requiring roughly another 4.6× log speedup.

Selections remain 21/809/9424/30483 at 32/1,000/10,000/100,000 items. Maximum relative criterion difference is 1.78e-15 versus linear, 5.97e-16 versus the previous log control. New log selection allocates a constant 4,240 bytes at the three larger sizes; individual prepared candidates allocate zero.

LLVM and remaining work

The producer now contains four-wide Float64 arithmetic and vector table gathers, with no generic apply or out-of-line exp/log1p calls. Previously it had eight scalar math call sites and only two-wide channel operations. Producer IR grows from 400 to 1,165 lines as Base's transcendental implementations are inlined. Moment reductions remain four-wide. The generic PBB loop needed no additional changes.

The remaining cost is the expanded transcendental algorithms, their table access and control flow; enabling SIMD alone does not remove that work. A separate maximum pass did not help, and a guarded probability-space prototype offered only a modest extra gain for substantially more conditions/fallback logic, so neither was adopted.

Driver: CATExperiments/bench/log_optimisation_20261109/next_step/run.jl. Raw samples, correctness checks, source revisions, dependency manifest and LLVM are retained locally in CATExperiments/data/analysis/20261109-log-vectorized/; these are not claimed to be published repository artifacts.

@coveralls

coveralls commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 42685150389

Warning

No base build found for commit f5dcc79 on codex/grid-preallocation-scratch.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 54.949%

Details

  • Patch coverage: 9 of 9 lines across 1 file are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 2455
Covered Lines: 1349
Line Coverage: 54.95%
Coverage Strength: 217111.5 hits per line

💛 - Coveralls

This branch has not been deployed

No deployments
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.

2 participants