perf: add ARM64/WASM scalar fast path for Premultiply/UnPremultiply#1
Closed
kodroi wants to merge 1 commit into
Closed
perf: add ARM64/WASM scalar fast path for Premultiply/UnPremultiply#1kodroi wants to merge 1 commit into
kodroi wants to merge 1 commit into
Conversation
kodroi
force-pushed
the
perf/fuse-premultiply-simd
branch
2 times, most recently
from
April 1, 2026 07:45
2454336 to
a0f51b7
Compare
On x86, keep the existing PermuteW+WithW path which generates optimal vpermilps+vinsertps with a single memory load/store (14-23 cycles, as recommended by @tannergooding in PR SixLabors#2369). On ARM64/WASM where SSE is unavailable, PermuteW and WithW fall through to scalar code but still incur method call overhead. Add a direct scalar path that avoids the helper call chain while producing identical results. Profiled with metreja.io on a 2048x2048 RGBA32 image (50x Resize + 20x GaussianBlur), .NET 10.0.2 ARM64: Premultiply (inclusive): 11,614s -> 611s (-95%) PermuteW: 1,029s -> 0s (-100%, not called) WithW: 1,077s -> 0s (-100%, not called) UnPremultiply (inclusive): 947s -> 39s (-96%) Convolve4 (inclusive): 6,559s -> 417s (-94%) No change on x86 (same code path as before). All 38,330 tests pass (net8.0, macOS ARM64). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
kodroi
force-pushed
the
perf/fuse-premultiply-simd
branch
from
April 1, 2026 08:46
a0f51b7 to
a0b612d
Compare
Owner
Author
|
Closing — with JIT inlining enabled (realistic profiling), PermuteW and WithW are fully inlined and the ARM64 scalar fast path shows ~0% measurable difference. The original profiling numbers were inflated by metreja's COR_PRF_DISABLE_INLINING flag, which has since been fixed in metreja v1.0.20. |
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.
Prerequisites
Description
On x86,
PremultiplyandUnPremultiplyusePermuteW()+WithW()helpers which generate optimalvpermilps+vinsertpswith a single memory load/store (14-23 cycles, as recommended by @tannergooding in PR SixLabors#2369).On ARM64/WASM where SSE is unavailable, these helpers fall through to scalar fallbacks but still incur method call overhead across a 3-level call chain (
Premultiply → PermuteW/WithW → scalar). This PR adds a direct scalar path behindif (Sse.IsSupported)that avoids the helper call chain on non-x86 platforms while keeping the existing x86 behavior unchanged.Profiled with metreja.io on a 2048x2048 RGBA32 image (50x Resize + 20x GaussianBlur), .NET 10.0.2 ARM64:
Times are cumulative profiler-instrumented across the entire workload. No change on x86 (same code path as before).
All 38,330 existing tests pass. DLL size unchanged.