Repository navigation
Inherit page-tree attributes in one top-down pass - #603
Merged
Merged
Conversation
Decoding the page tree applied each /Pages node's inherited attributes to every descendant at every level, so a page with its own /Resources was merged once per resource-carrying ancestor, and pages sharing one /Resources dictionary each got their own deep copy. The tree is now decoded as written and flattened once from the root: each node combines with its ancestors once, each page is merged at most once, and merges are shared between pages that point at the same resources below the same ancestors. Resources::merged_with_parent returns None when the parent adds nothing, so the child's resources are kept as they are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Opening a document re-merged each page's inherited
/Resourcesat every level of the page tree. Pages that share one/Resourcesdictionary also each got their own deep copy. Moving thePdfPagevalues themselves was cheap (about 120 bytes per move, no heap data copied).Resources::merged_with_parentskips needless merges. It returnsNonewhen the parent defines nothing the child lacks, so the child'sArcis kept. It used to returnSomeevery time.PageTreeBranchreads each/Pagesnode exactly as written, thenPageTreewalks down the tree once from the root. Each node combines with its ancestors once, each page is merged at most once, and each page is moved once into the finalVec.ResourceMergescache, keyed on the (own, inherited)Arcpointers, gives pages that share/Resourcesunder the same ancestors one shared merged copy.One test assertion changed:
leaf_page_child_entries_take_priority_during_inheritancenow expects the child's ownArcback, because there the parent adds nothing.Measurements
Release profile (opt-level "z", fat LTO), base vs. change alternating over 5 rounds, best time per document:
/Resourcesexamples/assets/*(8 documents)Test plan
cargo testcargo clippy --workspace --all-targets -- -D warnings,cargo fmt --check🤖 Generated with Claude Code