Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-4668

Add ResourceCacheFactory as global setting

    XMLWordPrintableJSON

Details

    • Task
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • Rendering
    • None

    Description

      Image rendering is cached by DefaultResourceCache per-document using soft references. As described in the FAQ, this can lead to an OutOfMemoryError when processing, e.g. many documents in parallel. The configuration of this cache is per-document and it is initialized with the default.

      // document-wide cached resources
      private ResourceCache resourceCache = new DefaultResourceCache();
      

      This requires all call sites be modified to disable it, some of which may be in 3rd party code. The ask is to static factory to configure the default globally, which would return a new DefaultResourceCache when called. This would let a user specify a new static factory, e.g. one that returns a custom cache or null if disabled.

      Soft references are a problematic caching scheme, which degrades poorly. It is very likely that the many and large image fragments causes GC promotion (eden=>young=>old) which requires a full GC to collect. Under memory/cpu pressure, the GC can devolve into a death spiral of collecting the minimal heap space to match its pause time constraints, leading to repeated GCs due to soft reference pollutions and an eventual OOME. If caching was set, it might be preferable to be size-based (by rough byte-size) and perhaps tied into MemoryUsageSetting main memory configuration.

      Attachments

        1. threads.png
          1.60 MB
          Ben Manes
        2. Screenshot 2023-03-20 at 18.57.40.png
          965 kB
          Valentin Popov
        3. memory.png
          1.14 MB
          Ben Manes

        Activity

          People

            Unassigned Unassigned
            ben.manes Ben Manes
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: