Repository navigation
Conversation
Contributor
FastInterpolations.jl Benchmarks
All benchmarks (71 total, click to expand)
This comment was automatically generated by Benchmark workflow. |
Evaluating an all-Cardinal, non-periodic `HeteroInterpolantND` ran a full 1D
one-shot for each fiber, plus pool buffers per level. A cardinal fiber is linear
in its stencil values, with coefficients that depend only on the axis and query,
so resolve four weights once per axis for the requested eval op and fold the
stencil as weighted sums.
On a 64^3 grid (Apple M5, Julia 1.14.0-alpha2), 3D evaluation drops from 76 to
29 ns for `SVector{3,Float64}` data and from 52 to 21 ns for `Float64`. Results
change by rounding only. The `@noinline` boundary at 4+ axes is what keeps
compile time bounded: without it the first 4D call took 37 s rather than 0.65 s.
Beforerr
force-pushed
the
perf/cardinal-nd-cell-fold
branch
from
November 4, 2026 03:05
491e81e to
009ef6c
Compare
This branch has not been deployed
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.
Problem
Evaluating an all-Cardinal, non-periodic
HeteroInterpolantNDis much slower than its stencil requires. On a 64³ grid, a 3D evaluation takes about 76 ns forSVector{3,Float64}data and 52 ns forFloat64. A hand-written Catmull-Rom takes about 25 ns forSVector{3,Float64}.Root cause
_collapse_dimsruns a full 1D one-shot for each of the 21 fibers in 3D, repeating the search and setup, and acquires pool buffers at each level. A Cardinal fiber is also linear in its stencil values, with coefficients that depend only on the axis and query.Fix
Add a more specific
_collapse_dimsmethod for tuples of two or moreCardinalInterp{<:Any, NoBC}axes:Existing callers need no changes. That includes derivative ops and periodic axes that the wrap-aware path has already stripped to
NoBC. PCHIP, Akima, global-solve methods and mixed tuples stay on the existing fiber path, though an all-Cardinal tail of a mixed tuple does use the new method.Tuples of four or more axes go through a
@noinlineboundary to limit generated code size.Extrapolation is not re-applied per fiber. The method relies on callers having already applied it to
q_eval, and uses a two-sided clamped search so indices stay in range.How verified
Benchmarks on an 64³ grid, 3D evaluation:
SVector{3,Float64}Float64Native code for the
SVectorcall drops from about 18.8k to 1.1k instructions.Results change by rounding only, because weighted sums replace the kernel's secant differences. For example, a constant field of 1.1 now evaluates with an error of about 2e-16 at one test point, where it was exact.
The new
test/test_cardinal_cell_fold.jlcompares against nested 1Dcardinal_interpcalls along whole fibers. It coversn = 2, 3, 4, 5, 8, uniform and non-uniform grids, tension, derivatives,SVectordata, knots and extrapolated queries. It also checks that a NaN inside the fixed window but outside the end cell's stencil stays out of the result, and that evaluation doesn't allocate.