Repository navigation
perf(jpx): tier-1 decoding at 41 ns per sample (#255) - #502
Merged
Merged
Conversation
…tier-1 benchmark Packed stripe-column state, MQ registers in locals with a mostly branch-free DECODE, unrolled rows and a stripe-column reconstruction take tier-1 on issue5567 from 87 to 41.5 ns per sample (Native AOT, M4). Samples are identical on every corpus image and vector. Adds JpxTier1Benchmarks, MQ register-path tests, a per-code-block allocation test, the conformance row and docs/benchmarks/jpx-tier1.md.
…px-tier1-speed # Conflicts: # bench/baselines/gate/allocations.json # docs/conformance/iso-32000-2.md
Owner
Author
|
Merged spec/33-broadside-v1 at 13233b6 (#477's vectorized wavelet and the RCT/ICT changes). I kept both sides of allocations.json and of conformance row 7.4.9. On the merged tree the 217 sample hashes are unchanged, and the JPX and MQ tests pass (150 and 5). Whole decode of issue5567 is now 215.0 ms, 42.5 ns per sample on JIT; it was 238.3 ms with the tier-1 change alone. |
This was referenced Nov 12, 2026
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 #255 (the tier-1 part; the vertical wavelet pass and the component transforms are #477, in parallel).
Summary
JPEG 2000 tier-1 (ITU-T T.800 Annex D) was almost all of the first build of a page with a large JPX image (#352). It is now about 2.1x faster with sample-identical output:
uintper stripe column holds the 3 x 6 neighborhood significance, the column's signs and the refined/coded-this-plane bits, so every context is a table lookup on bits of one word (Tables D.1 to D.4). Idle columns are skipped on one test. Vertically causal contexts (D.7) come from not propagating a stripe's first row upward.refarithmetic over arrays sized for the block and its border).MqDecoder.Decode(ref byte, ReadOnlySpan<byte>, ref uint, ref uint, ref int, ref int), inlines BYTEIN, renormalizes by the leading zeros of A, and is branch-free apart from the common no-renormalization MPS case. JBIG2 keeps the existing path.Profile (Native AOT,
sample,pdfjs/issue5567.pdf, 1500 x 1125 lossless, 5.06 M samples)Target
Tier-1 at most 45 ns per sample on the heaviest corpus image (issue5567) on an Apple M4: measured 87 ns before and 41.5 ns after (Native AOT). The whole decode goes from 96.1 to 50.1 ns/sample (AOT) and from 91.5 to 47.1 (JIT); OpenJPEG 2.5.4 single-threaded takes 235 ms on the same image, against our 238 ms (JIT).
JpxTier1Benchmarks(random-data blocks, decisions close to even, the hard case):Default123.2 to 75.8 ns/sample,BypassCausal97.0 to 56.3,Allocated-. I have no CI-runner figure; the issue's 40 ns on the CI runner is not claimed. The bench-gate run will show the runner's numbers.Identical output
RealWorldJpxTestspasses againstjpx-corpus-references.txt, along with every OpenJPEG vector and reduced decode (JpxDecodeFilterTests,JpxScaledDecodeTests).JpxSamplesvector and the J.11 example,tests/CorpusJPX files, the moon memo sample, the fuzz seed) are identical before and after.MqDecoderTestscompares the register path with DECODE decision by decision.Broadside.Tests(14,827) andBroadside.Rendering.Tests(1,445) pass.Allocations
Zero per code-block (
JpxAllocationTests.Tier_1_allocates_nothing_per_code_block). Existing gate figures are unchanged:--gate-allocationsgives the same bytes as base for every JPX case. The only baseline edit is two new lines, both0, forJpxTier1Benchmarks. Contexts staybytefor that reason: keeping each context's whole table word would have been 3.5% faster but would change each decode's allocation.Fuzz
--smoke filter-jpx 120: 182 corpus files passed, 49,393,583 mutated inputs, no failures (plus a 60 s rerun after the last change: 21.7 M, no failures).Whole render (first render, 96 DPI, document reopened every pass, best, ms, M4 Max)
pdfjs/issue5567.pdfpdfjs/issue5481.pdfpdfjs/issue5549.pdfpdfium-tests/fx/action/123.pdfscan-moon-memo-jpx.pdfThe browser builds are a
browser-wasmconsole app under Node 22, built with and withoutRunAOTCompilation. Neither browser build regresses. Details and method:docs/benchmarks/jpx-tier1.md.Conformance
ISO 32000-2
7.4.9row: addsJpxCodeBlockDecoder, the new tests and a tier-1 note (T.800 C.3.2 to C.3.4, D.1 to D.7). No public API change.