fix(writer): renumber objects densely on full save#71
Closed
Mythie wants to merge 1 commit into
Closed
Conversation
writeComplete previously preserved original object numbers from the registry, which left gaps whenever orphans were dropped during garbage collection. The resulting xref was sparse — /Size reported the max original number while the actual entry count was smaller, producing files where the trailer's stated size didn't match reality. Renumber reachable objects to a contiguous 1..N range in a single pass: walk the graph, build an old-ref → new-ref map, then remap refs inside each object as it's written. Dangling refs (targets not in the registry) become PdfNull per PDF 1.7 §7.3.10, since the old number no longer exists in the new file. Move the "objNum gen" key formatter onto PdfRef as an instance method (ref.key()) so it's reusable and self-describing, replacing the local helper in pdf-writer. Also bumps dev/runtime deps (oxlint 1.39→1.65, vitest 4.0→4.1, lint-staged 16.2→16.4, pkijs/asn1js/@noble/* patches, etc.) and drops @typescript-eslint/prefer-const from .oxlintrc.json since newer oxlint removed that alias — the core prefer-const rule still applies.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Benchmark ResultsComparisonLoad PDF
Create blank PDF
Add 10 pages
Draw 50 rectangles
Load and save PDF
Load, modify, and save PDF
Extract single page from 100-page PDF
Split 100-page PDF into single-page PDFs
Split 2000-page PDF into single-page PDFs (0.9MB)
Copy 10 pages between documents
Merge 2 x 100-page PDFs
Fill FINTRAC form fields
Fill and flatten FINTRAC form
CopyingCopy pages between documents
Duplicate pages within same document
Merge PDFs
Drawingbenchmarks/drawing.bench.ts
Formsbenchmarks/forms.bench.ts
Loadingbenchmarks/loading.bench.ts
Savingbenchmarks/saving.bench.ts
SplittingExtract single page
Split into single-page PDFs
Batch page extraction
Environment
Results are machine-dependent. |
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.
writeComplete previously preserved original object numbers from the
registry, which left gaps whenever orphans were dropped during garbage
collection. The resulting xref was sparse,
/Sizereported the maxoriginal number while the actual entry count was smaller, producing
files where the trailer's stated size didn't match reality.
Renumber reachable objects to a contiguous 1..N range in a single pass:
walk the graph, build an old-ref → new-ref map, then remap refs inside
each object as it's written. Dangling refs (targets not in the
registry) become PdfNull per PDF 1.7 §7.3.10, since the old number no
longer exists in the new file.
Move the "objNum gen" key formatter onto PdfRef as an instance method
(ref.key()) so it's reusable and self-describing, replacing the local
helper in pdf-writer.
Also bumps dev/runtime deps (oxlint 1.39→1.65, vitest 4.0→4.1,
lint-staged 16.2→16.4, pkijs/asn1js/@noble/* patches, etc.) and drops
@typescript-eslint/prefer-const from .oxlintrc.json since newer oxlint
removed that alias — the core prefer-const rule still applies.