Skip to content

perf(colors): vectorize the CMYK characterization and copy ICCBased samples with a device alternate (#476) - #494

Merged
michaelstonis merged 5 commits into
spec/33-broadside-v1from
476-simd-cmyk-icc
Nov 11, 2026
Merged

michaelstonis merged 5 commits into
spec/33-broadside-v1from
476-simd-cmyk-icc

Conversation

@michaelstonis

@michaelstonis michaelstonis commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Closes #476.

Profiled first (macOS sample, Native AOT, 96 DPI): color conversion was 33% of the catalogue's render time (the CMYK characterization and its callers) and 73% of the brochure's and the newsletter's (RGB images in ICCBased spaces converting through their DeviceRGB alternate, byte to float and back to the same byte). The showcase spends under 1% there. The ICC engine's matrix/TRC (IccTransform in Broadside.Rendering) only runs with UseIccColorManagement, so it is not on these paths and is not vectorized here.

Changes

  • CmykCharacterization.ToRgbRowVector: the SWOP polynomial for four colors per iteration in two pairs of Vector128<double> lanes, in the scalar term order (bit-exact). DeviceConverter keeps its run detection and converts each stretch of distinct colors as one row. Gated off in the browser (!OperatingSystem.IsBrowser(), as the box filter): the blazor-wasm job measured 0.89x in the interpreter build (2.78x in AOT, which cannot be told apart at run time).
  • ICCBased with a device alternate copies its 8-bit samples when the alternate is the target model and all ranges are 0..1, as DeviceRGB and DeviceCMYK already did.
  • ColorMath.Clamp01 inlines (two comparisons, the same bits); the per-sample range lookups no longer take i % inputs.
  • CmykCharacterizationBenchmarks (gate entries at 0), a cmyk-to-rgb case in the Blazor KernelBenchmarks, conformance rows for §8.6.5.5 and §10.4, and a section in docs/benchmarks/simd-kernels.md.

Speed

Kernel, ns per color, scalar → vector: JIT 20.2 → 12.8 (1.58x), Native AOT 20.2 → 9.9 (2.04x), browser interpreter CI 618 → 694 (0.89x, hence the gate; 1.44x locally under Node), browser AOT CI 146 → 53 (2.78x). BenchmarkDotNet, 794 colors: 14.66 → 7.34 µs, Allocated -.

Whole documents (every page, 96 DPI, ms per pass). Native: base before #472; browser: base the integration branch after #472, head this change merged onto it (scalar kernel in both browser builds):

Document JIT Native AOT Browser interpreter Browser AOT
brochure 155 → 52 (-67%) 184 → 51 (-72%) 5,161 → 1,285 (-75%) 372 → 95 (-75%)
newsletter 233 → 77 (-67%) 290 → 76 (-74%) 7,868 → 1,570 (-80%) 597 → 143 (-76%)
catalogue 979 → 861 (-12%) 995 → 806 (-19%) 29,321 → 16,507 (-44%) 1,800 → 1,579 (-12%)

Bit-exact

  • CmykCharacterizationKernelTests (SimdKernel category): 20 million 8-bit colors, special values (NaN, ±0, denormals, out of range, infinities) at every short length and offset, the dispatcher, and runs of equal colors against per-color conversion. Passes with DOTNET_EnableHWIntrinsic=0 too.
  • Goldens and snapshots (Broadside.Rendering.Tests, 1,442) pass; page 0 of 1,228 files (pdf.js corpus, GWG output suite, PDF 2.0 examples, sample documents; 1,113 render) hash identically before and after.

…amples with a device alternate (#476)

The SWOP polynomial converts runs of distinct colors four at a time in Vector128<double> lanes, in the scalar term order (bit-exact,
checked over 20 million 8-bit colors and the clip's special values). 8-bit samples of an ICCBased space whose alternate is the target
device space with 0..1 ranges are copied, as DeviceRGB samples already were. Clamp01 inlines, and the per-sample range lookups no
longer take a modulo.
…imd-cmyk-icc

# Conflicts:
#	docs/conformance/iso-32000-2.md
#	samples/Broadside.Viewer.Blazor.Sample/KernelBenchmarks.cs
… browser (#476)

The blazor-wasm job measured it at 0.89x in the interpreter build (2.78x in the AOT build, which cannot be told apart at run time);
the browser figures are remeasured against the integration branch after #472.
#476)

The gate reported only the eight SkiaFirstTileBenchmarks.FirstTile cases, each 160 B per call above the baseline (single cold
invocations, which include the color pipeline's one-time setup); every other case is unchanged.
@michaelstonis
michaelstonis merged commit 6ab3993 into spec/33-broadside-v1 Nov 11, 2026
32 checks passed
@michaelstonis
michaelstonis deleted the 476-simd-cmyk-icc branch November 11, 2026 07:04
michaelstonis added a commit that referenced this pull request Nov 11, 2026
…red values

The eight SkiaFirstTileBenchmarks.FirstTile entries measured 288 B under
the baseline in every gate run of this branch (identical values on four
attempts, before and after merging #494); set them to those values.

Signed-off-by: Michael Stonis <120685+michaelstonis@users.noreply.github.com>
michaelstonis added a commit that referenced this pull request Nov 11, 2026
* perf(filters): vectorize the 8 x 8 islow inverse DCT (#474)

- InverseDct.TransformVector runs libjpeg's jpeg_idct_islow four columns,
  then four rows, at a time in 32-bit Vector128 lanes: pass 1 works on the
  coefficient rows as loaded, its results are transposed with constant
  byte shuffles and selects, and pass 2's outputs are packed back into rows
  by multiplies. The range-limit table becomes a sign-extend and clamp.
- Bit-exact with the scalar port, which stays as TransformScalar and the
  fallback: libjpeg's column shortcut is computed and selected per lane
  (the full arithmetic differs where the DC term wraps); its row shortcut
  equals the full arithmetic in the 10 bits the range limit keeps.
- Left shifts are multiplies: the browser AOT build runs a vector shift at
  several times their cost.
- InverseDctKernelTests (every single-coefficient block, sparse and
  full-range random blocks, a wider stride), InverseDctBenchmarks with
  allocation baseline entries at 0, and an idct-8x8 KernelBenchmarks case.

Signed-off-by: Michael Stonis <120685+michaelstonis@users.noreply.github.com>

* docs(benchmarks): record the #474 inverse DCT kernel

Signed-off-by: Michael Stonis <120685+michaelstonis@users.noreply.github.com>

* docs(benchmarks): add the CI browser figures for the #474 inverse DCT

Signed-off-by: Michael Stonis <120685+michaelstonis@users.noreply.github.com>

* test(direct2d): assert WIC beats the managed decoder only with subsampled chroma

With the vector IDCT (#474) the managed decoder matches or beats WIC's
pixels on the 8-megapixel 4:4:4 photograph (0.82x in two of three CI runs,
1.9x to 2.0x before). The 4:4:4 case is measured and logged; the default
decoder choice is unchanged.

Signed-off-by: Michael Stonis <120685+michaelstonis@users.noreply.github.com>

* chore(bench): set the SkiaFirstTile allocation baselines to the measured values

The eight SkiaFirstTileBenchmarks.FirstTile entries measured 288 B under
the baseline in every gate run of this branch (identical values on four
attempts, before and after merging #494); set them to those values.

Signed-off-by: Michael Stonis <120685+michaelstonis@users.noreply.github.com>

---------

Signed-off-by: Michael Stonis <120685+michaelstonis@users.noreply.github.com>
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.

1 participant