Add opt-in content spooling to lower retained memory#829
Open
splitbrain wants to merge 1 commit into
Open
Conversation
Add Config::setContentSpooling(): when enabled, each parsed object's decoded stream content is written to a single temporary file (ContentSpool) and read back on demand via PDFObject::getContent(), instead of being held in memory for the document's lifetime. The temp file is removed automatically once the document is destroyed. This lowers the memory retained after parsing and during text extraction; extracted text and document details are byte-for-byte identical with the option on or off (verified across the sample suite). Measured memory retained after parsing (getText output identical), vs master: samples/bugs/PullRequest457.pdf 71 MB -> 30 MB (-58%) samples/DocumentWithLotsOfObjects.pdf 55 MB -> 32 MB (-41%) samples/bugs/Issue356.pdf 25 MB -> 2 MB (-93%) samples/bugs/Issue391.pdf 5 MB -> 2 MB (-62%) Note: on documents whose peak occurs while the raw object graph is being built, spooling alone does not lower the peak - it pairs with incremental object construction, which removes that earlier peak.
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.
Part 3 of #824
Add Config::setContentSpooling(): when enabled, each parsed object's decoded stream content is written to a single temporary file (ContentSpool) and read back on demand via PDFObject::getContent(), instead of being held in memory for the document's lifetime. The temp file is removed automatically once the document is destroyed.
This lowers the memory retained after parsing and during text extraction; extracted text and document details are byte-for-byte identical with the option on or off (verified across the sample suite).
Measured memory retained after parsing (getText output identical), vs master:
samples/bugs/PullRequest457.pdf 71 MB -> 30 MB (-58%)
samples/DocumentWithLotsOfObjects.pdf 55 MB -> 32 MB (-41%)
samples/bugs/Issue356.pdf 25 MB -> 2 MB (-93%)
samples/bugs/Issue391.pdf 5 MB -> 2 MB (-62%)
Note: on documents whose peak occurs while the raw object graph is being built, spooling alone does not lower the peak - it pairs with incremental object construction (#827), which removes that earlier peak.