feat(pdf): share one image across the pages that place it - #751
Open
andiwand wants to merge 1 commit into
Open
Conversation
The pdf view inlined every image as a data url and ignored `HtmlConfig::embed_images`, so a logo on all 100 pages was base64'd 100 times. On the private corpus that is 29.7M of a 49.5M render, and it is duplication across pages, not within one, so a `<defs>`/`<use>` collapse would not reach it. `ImageRegistry` keys on the image XObject, which the parser memoizes per document, so its address identifies a repeat — no digest over the bytes. The resource is named by a counter and run through the config's resource locator: embedded as today by default, written once and linked when `embed_images` is off. An inline (`BI`) image and a stencil get an entry each, a stencil's bytes following the fill colour. Default output is byte-identical. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0169dUoxqhqfi7ZU5ei8b9ov
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.
🤖 Generated with Claude Code
Stacked on #750, which is stacked on #749.
The pdf view inlined every image as a data url and ignored
HtmlConfig::embed_images— every other view honours it. A logo on 100 pages was base64'd 100 times.Measured on the private pdf corpus, splitting duplication by where it occurs:
Rockrider_e-Actv500_Allgemein_und_GarantieRockrider_e-Actv500_GebrauchsinformationenLaserentfernungsmesser_PLEM50_D5Normstahl_UltraS_Garagentorantrieb_HansIt is almost entirely across pages, so collapsing repeats inside one page with
<defs>/<use>would recover close to nothing. Sharing a resource does.How
ImageRegistrykeys on the image XObject. The parser already memoizes those per document, so the address identifies a repeat and no digest over the bytes is needed — the resource is named by a plain counter, and the extension comes fromfile_type_by_mimetype/file_extension_by_file_typerather than a new table.The resource goes through
config.resource_locator, so:embed_imageson (the default) — a data url, exactly as todayembed_imagesoff —image1.jpgwritten once, linked from every page that places itAn inline (
BI) image and a stencil get an entry each: a stencil's bytes are built from the fill colour in effect, so two placements in different colours are genuinely different images.Verification
Note for the apps
The saving only lands when the host sets
embed_images = false. Before this PR that flag did nothing for pdf, so nothing changes until an app opts in.