Skip to content

Comments

4x Faster BlurHash decoding with optimized algorithm#69

Merged
Solido merged 4 commits intofluttercommunity:masterfrom
Rahiche:ft/optimized-blurhash
Apr 19, 2025
Merged

4x Faster BlurHash decoding with optimized algorithm#69
Solido merged 4 commits intofluttercommunity:masterfrom
Rahiche:ft/optimized-blurhash

Conversation

@Rahiche
Copy link
Collaborator

@Rahiche Rahiche commented Apr 19, 2025

Key Changes

Added a new BlurHashOptimizationMode enum with three options:

  1. none: Uses the original algorithm (default to be backward compatible)
  2. standard: Optimized with better cache locality (1.9)
  3. approximation: Fast approximation with simplified sRGB conversion (a slightly darker tint)

standard mode does the following:

  • Improved cache locality
  • Pre-calculated cosine values to avoid redundant computations

approximation mode add this:

  • faster approximation method for sRGB conversion

Migration

This change is fully backward compatible. The default optimizationMode for BlurHashWidget is set to none, so existing code will continue to use the original algorithm. To take advantage of the optimizations, users can set the optimizationMode parameter to standard or approximation.

Mode Comparison Screenshots

Standard Mode (Release Mode) (1.9x faster)

Standard Mode

Size Screenshot
512×512 Screenshot 1
256×256 Screenshot 2
128×128 Screenshot 3
64×64 Screenshot 4

Approximation Mode (Release Mode) (4x faster)

Size Screenshot
512×512 Screenshot 5
256×256 Screenshot 6
128×128 Screenshot 7
64×64 Screenshot 8

@Solido Solido merged commit 686e168 into fluttercommunity:master Apr 19, 2025
@mark8044
Copy link

@Rahiche Standard mode is working very well, I can't even notice a difference from default. very nice.

However approximation mode creates a weird pixelated shape

None/Standard:
Screenshot 2025-04-20 at 7 50 37 AM

Approximation:
Screenshot 2025-04-20 at 7 51 15 AM

Blurhash i was using for this picture: A44.JD_48_4n

This is happening for any blur hash I throw at it

@Rahiche
Copy link
Collaborator Author

Rahiche commented Apr 20, 2025

Thanks for catching this @mark8044
if you can create an issue I'll make a fix ASAP

@fingerart
Copy link

@Rahiche Where is the source code of benchmarks?

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.

4 participants