Repository navigation
perf(jpx): fuse and vectorize the 9/7 rounding with the DC level shift (#503) - #504
Merged
Merged
Conversation
Owner
Author
|
blazor-wasm job (run 43130314820): |
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.
Closes #503.
After #477 the 9/7 rounding before the DC level shift (
JpxDecoder.RoundToIntegers) was 10% ofpdfium-tests/fx/action/123.pdf's render, more than the wavelet. It was a full scalar pass writing integers back in place, andJpxPlane.Writethen read the buffer again with 64-bit arithmetic and a column check per sample.Approach
JpxLevelShift.RoundShift:round(clamp(v, -shift, max - shift)) + shift, NaN as 0; rounding is monotone and fixes integers, so clamping first gives the old result). The 5/3 path (Shift) clamps before adding so the 32-bit sum cannot overflow. Components deeper than 16 bits keep the old rounding and 64-bit path.Vector128path, 8 samples per iteration: NaN masked withEquals(x, x),Max/Minclamp, rounding by adding 1.5 x 2^23 (the add itself rounds to nearest, ties to even), packed to 16 bits with two constant byteShuffles (no 32-bitNarrow). Scalar fallback byVector128.IsHardwareAccelerated.Bit-exact
JpxLevelShiftKernelTests(SimdKerneltrait, also passes withDOTNET_EnableHWIntrinsic=0), depths 1 to 16: vector and dispatcher vs scalar, and scalar vs the replaced round-then-shift code, over special values (NaN payloads, infinities, signed zeros, denormals, extremes, every half-integer around and between the bounds with neighbors one ulp away) and 4 million random floats; 5/3 over every integer in [-70,000, 70,000], the 32-bit extremes and a million random integers.RealWorldJpxTestsagainst the fetched corpora (jpx-corpus-references.txt) included. Decoded samples of 150 dumped JPX streams and vectors at reductions 0 to 2 (212 SHA-256) and every page of the 25 JPX corpus files at 72 and 150 DPI hash identically before and after.Speed (ns/sample, 64 Ki samples, before / scalar / vector; local, Node 22 for the browser builds)
BenchmarkDotNet
JpxLevelShiftBenchmarks(JIT, short):RoundThenShift95.9 µs,RoundShift11.6 µs,Shift8.5 µs,Allocated-. No build is gated. Thejpx-shiftandjpx-round-shiftKernelBenchmarkslines from the blazor-wasm job are in a comment below.Whole render (best pass ms, every page at 96 DPI, documents opened afresh): 123.pdf Native AOT 51.7 to 41.4 (-20%), browser AOT 96.9 to 75.6 (-22%), interpreter 1,088 to 956 (-12%); scan-moon-memo-jpx.pdf -25% / -26% / -22%; #352's pages (issue5567, issue5481, issue5549) -2% to -6%, being 87-91% tier-1. Details in
docs/benchmarks/simd-kernels.md.