Skip to content

Add opt-in content spooling to lower retained memory#829

Open
splitbrain wants to merge 1 commit into
smalot:masterfrom
cosmocode:mem/content-spooling
Open

Add opt-in content spooling to lower retained memory#829
splitbrain wants to merge 1 commit into
smalot:masterfrom
cosmocode:mem/content-spooling

Conversation

@splitbrain

Copy link
Copy Markdown

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant