Skip to main content

Module flatten_cache

Module flatten_cache 

Source
Expand description

Content-addressed cache for flattened XFA output (#468).

Flattening an XFA form costs 117 to 729 ms on the corpus documents the editor measured, and the render path used to pay it again on every render call. The flatten is a pure function of the input bytes (and of the XFA_* environment switches the pipeline reads), so the cache key is a SHA-256 over exactly those, and nothing else:

  • Invalidation is by construction. A mutation that changes any byte of the document yields a different key and therefore a miss. There is no invalidation call a caller can forget, and no path by which a stale flatten can be served for changed input.
  • What it does not do. A mutation that changes bytes is a full flatten again. Skipping that needs a proof that the changed bytes cannot reach the flatten, and the flatten reads the whole file (embedded images, fonts, the static fallback), so no such proof is attempted here.

Only successful flattens are stored, so an error is never replayed. The cache is bounded by entry count and by total bytes; the least recently used entry goes first.

Structs§

FlattenCache
A bounded, thread-safe flatten cache. Most callers want the process-wide one behind flatten_cached; the type is public so a host can own a separate instance with its own bounds.
FlattenCacheStats
Counters for observing the cache. hits + misses is the number of lookups.
FlattenKey
Identity of one flatten input.

Constants§

DEFAULT_MAX_BYTES
Default bound on the total size of cached flattens (128 MiB).
DEFAULT_MAX_ENTRIES
Default bound on the number of cached flattens.

Functions§

clear
Drop every process-wide entry.
flatten_cached
crate::flatten::flatten_xfa_to_pdf through the process-wide cache.
invalidate
Drop the process-wide entry for exactly these input bytes.
stats
Counters of the process-wide cache.