Skip to content

Improving Fast Blur#2515

Merged
197g merged 4 commits intoimage-rs:mainfrom
awxkee:box_blur
Jul 6, 2025
Merged

Improving Fast Blur#2515
197g merged 4 commits intoimage-rs:mainfrom
awxkee:box_blur

Conversation

@awxkee
Copy link
Copy Markdown
Contributor

@awxkee awxkee commented Jun 29, 2025

Closes #2511

It’s possible to push it even further using a ring buffer and fixed point arithmetic, but that would at least double the amount of code, and this version already gives a nice performance boost.

Benchmark
fast blur: sigma 3.0    time:   [10.750 ms 10.758 ms 10.766 ms]
                        change: [-52.185% -52.000% -51.832%] (p = 0.00 < 0.05)

fast blur: sigma 7.0    time:   [10.851 ms 10.873 ms 10.896 ms]
                        change: [-51.702% -51.598% -51.494%] (p = 0.00 < 0.05)

fast blur: sigma 50.0   time:   [11.371 ms 11.426 ms 11.486 ms]
                        change: [-50.958% -50.681% -50.399%] (p = 0.00 < 0.05)

gaussian blur: sigma 3.0
                        time:   [9.4690 ms 9.7881 ms 10.273 ms]

gaussian blur: sigma 7.0
                        time:   [20.815 ms 20.922 ms 21.042 ms]

gaussian blur: sigma 50.0
                        time:   [173.84 ms 174.37 ms 174.92 ms]

gaussian blur (dynamic image): sigma 3.0
                        time:   [5.2525 ms 5.2611 ms 5.2702 ms]

gaussian blur (dynamic image): sigma 7.0
                        time:   [13.056 ms 13.084 ms 13.118 ms]

gaussian blur (dynamic image): sigma 50.0
                        time:   [94.538 ms 94.824 ms 95.138 ms]

@awxkee awxkee changed the title Make fast blur performance reasonable Improving Fast Blur Jun 29, 2025
@awxkee
Copy link
Copy Markdown
Contributor Author

awxkee commented Jul 3, 2025

PTAL?

@kornelski
Copy link
Copy Markdown
Contributor

It looks okay, but I'm not capable of verifying it is correct from just looking at the code. Last time I implemented such thing, I've had a bunch of off-by-ones or mixed-up offsets when radius was greater than image size.

The current tests only check pixels of an easy case, and the rest just checks for panics.

Maybe you could add more tests?

@awxkee
Copy link
Copy Markdown
Contributor Author

awxkee commented Jul 3, 2025

Done.
I believe it's not truly feasible to track all errors mentally in such algorithms, so I fuzz such algorithms, just as I fuzzed this one.

Copy link
Copy Markdown
Member

@197g 197g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Algorithmically I follow. But there are some style nits, the potential overflows would otherwise keep me up at night 🙂

Comment thread src/imageops/fast_blur.rs
Comment thread src/imageops/fast_blur.rs Outdated
Comment thread src/imageops/fast_blur.rs Outdated
@awxkee awxkee requested a review from 197g July 6, 2025 12:08
@awxkee
Copy link
Copy Markdown
Contributor Author

awxkee commented Jul 6, 2025

I’ve added a few asserts to make sure everything will go according to plan.

@197g 197g merged commit 98c41a4 into image-rs:main Jul 6, 2025
32 checks passed
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.

Fast blur is actually slow

3 participants