fix(store): devirtualize ND factory axis maps — zero-alloc Range builds#196
Merged
Conversation
…ange) With store=StorePolicy(copy=false, cache_axis=false) a trivial build must allocate nothing on Julia >= 1.12, measured through function barriers for 1D/ND x Vector/Range x forward-eval/one-shot-integrate. Every cell holds except ND Range axes, which leak a constant 416 B of build-time boxing — pinned RED ahead of the fix. Existing suites only asserted the relative raw < copying-build ordering, which let this absolute leak slip through.
…+ unit pins Lint testitem scans src/ and bans `map((…) -> _policy_axis/_store_axis/ _cache_axis(…), …)` closure-maps — the recurring alloc trap; RED at this commit against six legacy `_convert_copy(_cache_axis(…))` inner ctors. Also unit-pins the @generated axis-map helpers (including the hetero arm, whose end-to-end build has inherent allocations and cannot be pinned at zero) as zero-alloc on Range axes.
…zero The cache_axis work (#194) mapped per-axis wrap calls through closures capturing `store` (`map((g, bc) -> _policy_axis(g, bc, store), …)` and the inner-ctor `_store_axis` form with an `ntuple(_ -> Tg)` witness). On Julia 1.12 codegen leaves those per-axis calls dynamic for Range axes: runtime sparam computation plus a heap box of the isbits `_CachedRange` return — 416 B per 2-D build, paid by every forward and one-shot-integrate build with Range axes (Vector axes return heap pointers and stay clean, which is why the leak was Range-only). Replace the closure-maps with @generated unrolled helpers — `_policy_axes`, `_store_axes` (core + method-aware hetero arm), `_convert_cache_axes` — following the `_cache_axes_pooled` / `_resolve_axes` pattern, and convert all 11 call sites (5 store-policy maps + 6 legacy `_convert_copy` ctors), turning the source lint green. Zero-alloc build contract now holds across 1D/ND x Vector/Range x forward/one-shot integrate on Julia >= 1.12.
Contributor
FastInterpolations.jl Benchmarks
All benchmarks (56 total, click to expand)
This comment was automatically generated by Benchmark workflow. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #196 +/- ##
==========================================
+ Coverage 96.30% 96.33% +0.02%
==========================================
Files 164 164
Lines 13542 13554 +12
==========================================
+ Hits 13042 13057 +15
+ Misses 500 497 -3
🚀 New features to boost your workflow:
|
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.
Summary
The cache_axis work (#194) routed per-axis wrap calls through closure-maps (
map((g, bc) -> _policy_axis(g, bc, store), …)and the inner-ctor_store_axisform). On Julia 1.12, codegen leaves those per-axis calls dynamic for Range axes: runtime sparam computation plus a heap box of the isbits_CachedRangereturn — 416 B per 2-D build, paid by every ND forward and one-shot-integrate build with Range axes since #194. Vector axes return heap pointers and stay clean, which is why the leak was Range-only. Eval was never affected — only the build.Fix
Replace the closure-maps with @generated unrolled helpers —
_policy_axes,_store_axes(core + method-aware hetero arm),_convert_cache_axes— following the existing_cache_axes_pooled/_resolve_axespattern. All 11 call sites converted: the 5 store-policy maps from #194 plus 6 legacy_convert_copy(_cache_axis(…))inner ctors carrying the same shape.Build allocation,
copy=false(Julia 1.12, function-barrier measured)Tests — three-layer pin (TDD, red-first)
0 Bon Julia ≥ 1.12.src/(bare-function maps stay legal), so the pattern cannot silently return at any current or future call site. Red at introduction against the 6 legacy ctors, green after conversion.Also carries a small docs rider: a canonical
@docsblock forintegrate/cumulative_integratesomakedocscheckdocs = :exportspasses.