Skip to content

Add FastInterpolations as a faster resampling backend - #5706

Open
mgyoo86 wants to merge 5 commits into
MakieOrg:masterfrom
mgyoo86:feature/resampler-fastinterpolations-backend
Open

Add FastInterpolations as a faster resampling backend#5706
mgyoo86 wants to merge 5 commits into
MakieOrg:masterfrom
mgyoo86:feature/resampler-fastinterpolations-backend

Conversation

@mgyoo86

@mgyoo86 mgyoo86 commented Jul 18, 2026

Copy link
Copy Markdown

Hi!
I'm the author of FastInterpolations.jl, a new high-performance interpolation package, and I'm looking for more places to use it.
I found that Resampler (and its Pyramid payload) looks like a nice fit; it resamples on every pan/zoom, so faster interpolation helps interactivity.

This PR adds a small, shallow wrapper so Resampler (and its Pyramid payload) can use the FastInterpolations API through the existing method/mode keyword.

In the real per-frame resampling path, FastInterpolations is 2–9× faster than Interpolations.jl and matches the current output to floating-point round-off. So I made FastInterpolations.LinearInterp() the default; anything that already used Interpolations directly keeps working, and reverting the default is a one-line change.

In addition, the curvilinear contourf remap now also uses FastInterpolations — internal only, with identical output.

Benchmarks

Interpolations.jl's Linear() vs. the new default FastInterpolations.jl's LinearInterp(), measured through the real resample_image (the per-frame function):
a (2000x2000) source, either a Float32 field and an RGB{N0f8} photo-like image, downsampled to (500x500) for display.

Payload Interpolations FastInterpolations Speedup
Resampler Float32 1.25 ms 0.20 ms 6.1×
Resampler RGB{N0f8} 2.20 ms 0.98 ms 2.2×
Pyramid Float32 1.64 ms 0.19 ms 8.6×
Pyramid RGB{N0f8} 4.10 ms 0.59 ms 6.9×

The following is a benchmark script for the table above:

using Makie, BenchmarkTools, Colors
import FastInterpolations as FI
using Makie: Interpolations
const N0f8 = Colors.N0f8

N = 2000
f32 = Float32.(sin.((1:N) ./ 40) * cos.((1:N) ./ 50)')                       # outer product
rgb = RGB{N0f8}.(abs.(sin.((1:N) ./ 40)), abs.(cos.((1:N) ./ 50))', 0.4)     # real-photo type
X, Y = (1.0f0, Float32(N)), (1.0f0, Float32(N))
lim = Makie.Rect2f(1, 1, N - 1, N - 1)  
res =  (500, 500) # 2000² → 500² (4× downsample)

for (name, payload) in [
        "Resampler Float32 / Interpolations" => Makie.Resampler(f32; method = Interpolations.Linear()).data,
        "Resampler Float32 / FastInterp"     => Makie.Resampler(f32).data,
        "Resampler RGB / Interpolations"     => Makie.Resampler(rgb; method = Interpolations.Linear()).data,
        "Resampler RGB / FastInterp"         => Makie.Resampler(rgb).data,
        "Pyramid Float32 / Interpolations"   => Makie.Pyramid(f32; mode = Interpolations.Linear()),
        "Pyramid Float32 / FastInterp"       => Makie.Pyramid(f32),
        "Pyramid RGB / Interpolations"       => Makie.Pyramid(rgb; mode = Interpolations.Linear()),
        "Pyramid RGB / FastInterp"           => Makie.Pyramid(rgb),
    ]
    print(rpad(name, 36), ": ")
    @btime Makie.resample_image($X, $Y, $payload, $res, $lim)
end

This PR needs FastInterpolations 0.4.16, pinned in [compat].
Thanks for taking a look, any feedbacks and thoughts are welcome!

Resampler and its Pyramid payload now build interpolants with FastInterpolations (LinearInterp) instead of Interpolations (Linear). Passing an Interpolations degree still selects the old path, so the change is additive; output matches the previous linear result to floating-point round-off (Resampler ~1 ulp, Pyramid bit-identical). The curvilinear contourf remap also uses FastInterpolations now (internal, identical output).
@github-project-automation github-project-automation Bot moved this to Work in progress in PR review Jul 18, 2026
@mgyoo86

mgyoo86 commented Jul 27, 2026

Copy link
Copy Markdown
Author

For the maintainers' information:
the previous run (1333d98) passed all CI checks except the changelog one. I've now added a commit that only updates CHANGELOG.md, with no source code changes, so a full CI re-run probably isn't necessary.
Thanks!

@ffreyer

ffreyer commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

/benchmark 30

Oh, nvm, benchmarks don't work with branches on forks. I wanted to check if this influences using time, just in case

@mgyoo86

mgyoo86 commented Jul 29, 2026

Copy link
Copy Markdown
Author

For maintainters' information:
I’ve merged the latest master branch into this PR to resolve the conflict in the CHANGELOG.
(no conflicts in the actual source codes)

@ffreyer
I don’t think this will cause any performance issues, but… yes, it would have been better if the benchmark CI had been able to run on this PR.

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

Labels

None yet

Projects

Status: Work in progress

Development

Successfully merging this pull request may close these issues.

2 participants