Repository navigation
perf(rendering): decode build-time Flate images in slices (#566) - #579
Merged
michaelstonis merged 2 commits intoNov 18, 2026
Merged
Conversation
A display list built in slices (PdfPage.BeginDisplayList) now decodes the image of a top-level Do, and its soft mask, before the Do: the Flate filter inflates 16 KB and the predictor undoes 16 rows per step, and the interpreter reads the Do again once the decode is done. The samples, the list, the pixels and the diagnostics equal those of a list built whole. - StreamDecoder.ChainJob: the filter chain with resumable Flate and predictor stages; other filters run in one step. - Predictor.Run: the predictor's rows, shared by the one-step decode. - PdfImage.LoadJob: Prepare in slices. - DisplayListBuilder.PrepareImage: the image and soft-mask decode the Do takes. - Fuzz target filter-sliced compares sliced and one-step decodes. - Hot AOT profiles re-recorded for the new methods. Signed-off-by: Michael Stonis <120685+michaelstonis@users.noreply.github.com>
Signed-off-by: Michael Stonis <120685+michaelstonis@users.noreply.github.com>
Owner
Author
|
Benchmark gate: the only finding is |
3 tasks
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.
Resolves #566
What changed
A display list built in slices (
PdfPage.BeginDisplayList, which the browser viewer uses for tiles and for the page model) no longer decodes a Flate image inside theDothat paints it. Before a top-levelDoof an image XObject, the interpreter asks the builder to decode the image, then its soft mask, a slice at a time; when the slice's deadline passes the run pauses before theDoand reads it again on the next slice. TheDothen takes the decoded samples.StreamDecoder.ChainJob: the filter chain with resumable stages: Flate inflates 16 KB per step (FlateDecodeFilter.Inflation), the predictor undoes 16 rows per step (Predictor.Run). Other filters (LZW, CCITT, JBIG2, crypt, ASCII) run in one step, as do image codecs at the end of the chain (DCT and JPEG 2000 are kept encoded and already decode in slices at draw time, Smooth browser viewer without a second runtime: native image decode, sliceable decode, AOT demo #365).Predictor.Runis shared by the one-step decode (a struct, no allocation;FilterAllocationTestsunchanged).PdfImage.LoadJob:Preparein slices.DisplayListBuilder.PrepareImage/ImagePrefetch: decodes the image and, only under the conditionsDecodechecks before decoding one, its soft mask;InternImagetakes the result (and the epoch at which the decode started) or disposes it when the cache already had the image.OC, image masks, images inside forms and patterns, explicit masks, inline images.publish-static.sh --aot-profiler,AotProfileTests.Record_the_hot_aot_profile) so the new methods are compiled in--hot-aot.filter-sliced: the one-step and sliced decodes of any chain give the same bytes, outcome and diagnostics.The unsliced path (
CreateDisplayList, renders, extraction) is unchanged apart fromPredictor.Decodenow looping overPredictor.Run.Measurements
ScrollFrameTestsoncatalogue.pdf, Playwright Chromium, M4 Max, load 8 to 11. Before = #564's branch merged with thespec/33tip; after = that plus this PR (both local measurement trees, not pushed). Phone 390x844 @3x, CPU/4:Desktop rows unchanged (25 to 42 ms). Natively, the longest step of a sliced build of page 2 with a 2 ms budget falls from 12.7 to 16.0 ms to 2.4 to 3.1 ms (page 11: 12.4 to 16.1 → 2.4 to 2.5 ms).
--hot-aotdotnet.native.wasm: 11,592,220 bytes (cap 16,000,000)."Done when", item 2 is not met: the catalogue max frame with hot AOT on the phone stays at 93 ms (no worker) and 132 to 140 ms (worker, within the run-to-run noise the doc already records for that row). The Flate step is gone (interpreter frames halve, the viewer's own tile frame drops to 60 ms with hot AOT); with the worker the page thread draws no content, so what remains is the page model's other one-step items and the runtime (GC of a 290 to 590 MiB heap), not this decode. Written up in
docs/benchmarks/smooth-browser-viewer.md("Build-time Flate images (#566)").Verification
SlicedImageBuildTests(12 Flate variants: PNG and TIFF predictors, truncated, corrupt, raw deflate, unknown tags, partial rows, LZW, ASCIIHex+Flate, too long, soft mask of another size): list, samples, soft-mask samples, pixels and diagnostics equal the list built whole; cancellation mid-decode; cache reuse.SlicedChainDecodeTests(15 cases incl. decoded-length limit, empty, no filter): bytes, outcome and diagnostics equal.SlicedPreparationTests, golden images (Golden*), Core solution tests. In the full local run 13 allocation tests in unrelated areas (colour, JPX, function, shading) failed in Debug with the Homebrew SDK; they pass in Release with the canonical SDK (same on the base).dotnet run -c Release --project tests/Broadside.Fuzz -- --smoke filter-sliced 60: 190 corpus files passed, 6,778,772 mutated inputs in 60 s, no failures.dotnet format --verify-no-changeson Core and Fuzz.Notes for review
Maskentry are malformed,MaskKindis now read once more before theDo(the sink de-duplicates it).