Repository navigation
Embed images from buffers with the same bytes only once - #1851
Open
kroplabeskidu wants to merge 1 commit into
Open
kroplabeskidu wants to merge 1 commit into
kroplabeskidu wants to merge 1 commit into
Conversation
blikblum
reviewed
Nov 1, 2026
| key = src; | ||
| } else if (src instanceof Uint8Array || src instanceof ArrayBuffer) { | ||
| // by content, as a buffer can be changed or come from a pool | ||
| key = `md5:${md5Hex(src instanceof ArrayBuffer ? new Uint8Array(src) : src)}`; |
Member
There was a problem hiding this comment.
It is out of scope handling image data mutation. Add a weak map to the instance like was done in font
# Conflicts: # CHANGELOG.md
kroplabeskidu
force-pushed
the
dedupe-buffer-images
branch
from
November 1, 2026 15:42
e845473 to
fdf39bd
Compare
This branch has not been deployed
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.
What kind of change does this PR introduce?
Bug fix. Fixes #1361
An image from a file path is embedded once however often it is used, but one from a
Bufferwas embedded every time: the same 33 KB JPEG three times gave a 97 KB file.openImagenow also findsBuffer,Uint8ArrayandArrayBufferimages in the registry, by the MD5 of their bytes, which PDFKit already has for attachments.I used the bytes rather than the object, because a buffer can be changed between calls. It also catches separate buffers with the same image. The cost is hashing each buffer once per
image()call.Checklist: