Conversation
`_release_page_resources` cleared a page's rendered image only when `keep_images` was false, and `keep_images` is document-wide: it is true when any of `generate_page_images`, `generate_picture_images` or `generate_table_images` is set. One figure anywhere in the document therefore pinned *every* page's image until `_assemble_document` ran, even though only the pages carrying an element that step crops actually need it. On a 1356-page manual holding nine figures, that is the difference between growing ~14 MB per page and levelling off; peak RSS for a 600-page conversion fell from 5.5 GB to 1.4 GB. Decide per page instead: keep the image when page images are part of the requested output, or when the assembled page holds a `FigureElement` (with `generate_picture_images`) or a `Table` (with `generate_table_images`). A page that has not been assembled yet is kept, since what it holds is not known. `_assemble_document` maps those elements one-to-one onto the `PictureItem`s and `TableItem`s it crops, and enrichment steps re-render through the page backend, which `keep_backend` already preserves when they are enabled. Note for callers reading `conv_res.pages[i].image` after a conversion: pages without a figure now return None unless `generate_page_images` is set, which is the documented way to ask for page images. Signed-off-by: Junpei Kishi <junkreef@longarch.net> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
|
✅ DCO Check Passed Thanks @junkreef, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
_release_page_resources()cleared a page's rendered image only whenkeep_imageswasfalse, but
keep_imagesis document-wide: it is true when any ofgenerate_page_images,generate_picture_imagesorgenerate_table_imagesis set. Onefigure anywhere therefore pinned every page's image until
_assemble_documentran, somemory grew with the page count for the whole conversion.
The decision is now made per page. An image is kept when page images are part of the
requested output, or when the assembled page holds a
FigureElement(withgenerate_picture_images) or aTable(withgenerate_table_images). A page that hasnot been assembled yet is kept, since what it holds is not yet known.
This is safe because
_assemble_documentmaps those two element types one-to-one ontothe
PictureItems andTableItems it crops, and the enrichment steps re-render throughthe page backend, which
keep_backendalready preserves whenever they are enabled.Verification
A 1356-page manual containing 9 figures,
generate_picture_images=True,images_scale=2.0, first 400 pages:Per-page growth changes from a straight line (12.4 → 13.7 MB/page as the range grows) to
a curve that flattens (8.2 → 5.7 → 3.4 MB/page). The extracted figures are byte-identical
(SHA-256) and the text and table counts are unchanged.
tests/test_page_resource_release.pyis new: it exercises_page_image_has_consumerand_release_page_resourcesdirectly across the option combinations, with a stand-in thatcarries only the pipeline options, so no model is loaded. Eight of its eleven tests fail
on
v2.124.0.One behaviour note for callers: a page without a figure now returns
Nonefromconv_res.pages[i].imageunlessgenerate_page_imagesis set, which is the documentedway to ask for page images.
Issue resolved by this Pull Request:
Resolves #4163
Checklist:
documented contract changes)