-
-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add specialized matrix transform for Vector3 and Matrix3x3 #585
Conversation
Adds a specialized matrix multiplication function that transforms an array of length 3 with a 3x3 matrix. The specialized function can also transform the array in place which can eliminate one array allocation. The https://github.com/texel-org/color color library has a benchmark comparing itself to Color.js. Profiling the conversion benchmark showed that matrix multiplication was one of the areas that was taking the most amount of time. This PR speeds up the conversion benchmark by more than 3x and some of the other benchmarks by 2-3x Benchmark numbers before this PR: --------------------------------- conversion (Colorjs.io procedural API) -- Colorjs.io: 6213.74 ms Ours: 733.75 ms Speedup: 8.5x faster conversion (Colorjs.io main API) -- Colorjs.io: 25444.47 ms Ours: 703.50 ms Speedup: 36.2x faster gamut mapping OKLCH - sRGB (Colorjs.io procedural API) -- Colorjs.io: 13302.80 ms Ours: 72.97 ms Speedup: 182.3x faster gamut mapping OKLCH - sRGB (Colorjs.io main API) -- Colorjs.io: 14900.11 ms Ours: 67.78 ms Speedup: 219.8x faster gamut mapping all spaces to P3 (Colorjs.io procedural API) -- Colorjs.io: 10878.26 ms Ours: 201.85 ms Speedup: 53.9x faster gamut mapping all spaces to P3 (Colorjs.io main API) -- Colorjs.io: 13731.21 ms Ours: 201.76 ms Speedup: 68.1x faster After this PR: -------------- conversion (Colorjs.io procedural API) -- Colorjs.io: 1793.97 ms Ours: 713.03 ms Speedup: 2.5x faster conversion (Colorjs.io main API) -- Colorjs.io: 19884.18 ms Ours: 704.59 ms Speedup: 28.2x faster gamut mapping OKLCH - sRGB (Colorjs.io procedural API) -- Colorjs.io: 4981.04 ms Ours: 74.01 ms Speedup: 67.3x faster gamut mapping OKLCH - sRGB (Colorjs.io main API) -- Colorjs.io: 6477.12 ms Ours: 68.02 ms Speedup: 95.2x faster gamut mapping all spaces to P3 (Colorjs.io procedural API) -- Colorjs.io: 4205.36 ms Ours: 202.27 ms Speedup: 20.8x faster gamut mapping all spaces to P3 (Colorjs.io main API) -- Colorjs.io: 6137.99 ms Ours: 199.91 ms Speedup: 30.7x faster
✅ Deploy Preview for colorjs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! LGTM, one nit is that the name transform()
seems a bit too generic.
I agree but wasn't sure what to call it, I was hoping someone would suggest a better name 😃 |
It multiplies a vector of length 3 with a 3x3 matrix, right? What about |
Adds a specialized matrix multiplication function (
transform
) that transforms an array of length 3 with a 3x3 matrix. The specialized function can also transform the array in place which can eliminate one array allocation.The https://github.com/texel-org/color color library has a benchmark comparing itself to Color.js.
Profiling the conversion benchmark showed that matrix multiplication was one of the areas that was taking the most amount of time.
This PR speeds up the conversion benchmark by more than 3x and some of the other benchmarks by 2-3x.
Benchmark numbers before this PR:
After this PR:
There are still some color spaces that haven't been switched over to use the
transform
function. Assuming we want to proceed with this PR I'll create a separate PR to deal with the remaining spaces.