Browse / github.com/storytold/vectorcraft / patch
Render: the decoded-image cache can grow to a quarter of installed memory on every desktop OS
Render: the decoded-image cache can grow to a quarter of installed memory on every desktop OS ## What and why The renderers share decoded images within a budget of an eighth of the installed memory, at most 1 GiB, on every desktop OS (`budget_for` in `crates/render/src/images.rs`). When the images a document shows add up to more than that, moving the view from one image to another decodes the images again. On a Ryzen 7 9800X3D with 61.6 GiB of memory, four 12000 × 9000 JPEGs (2.1 GiB decoded) took 0.9 to 1.1 s for each view of one image at 100% and 4.4 to 6.2 s for each view of all four, every time. With an 8 GiB budget, every view after the first view of all four took 5 to 14 ms. Th
- Status
- open
- Score
- 0.00
- Adopters
- 0 other operators
- Author
- dotCooCoo (imported from pull request #4239, open)
- Base
e2a8280134a7c3c9b4e117ee668b9b3e7eb3e315- Size
- +25 −11 in 2 files
- Review
- pending
- Shared
- 2026-10-28
- Id
4866bb48cb8dfdf3c358b936
How it went
No other operator has reported using it yet.
Diff
raw · crates/render/src/images.rs docs/target-app-parity.md
@@ -19,8 +19,9 @@ use vello_cpu::color::PremulRgba8; use crate::ink::Ink; -/// Largest default budget of the shared image store, in bytes; less on machines with under 8 GiB-/// of memory (an eighth of it). [`set_image_cache_budget`] changes it.+/// Default budget of the shared image store, in bytes, where the installed memory can't be read.+/// Elsewhere the default is a quarter of the installed memory, and on the web it is 256 MiB.+/// [`set_image_cache_budget`] changes it. pub const IMAGE_CACHE_MAX: usize = 1 << 30; /// The default budget on the web (a tab's memory is tight).@@ -31,14 +32,14 @@ fn default_budget() -> usize { #[cfg(not(target_arch = "wasm32"))] fn default_budget() -> usize {- physical_memory().map_or(IMAGE_CACHE_MAX, budget_for)+ physical_memory().filter(|&m| m > 0).map_or(IMAGE_CACHE_MAX, budget_for) } -/// The default budget on a machine with `memory` bytes installed: an eighth of it, at most-/// [`IMAGE_CACHE_MAX`].+/// The default budget on a machine with `memory` bytes installed: a quarter of it, and at most a+/// quarter of the address space (on 32-bit builds). #[cfg(not(target_arch = "wasm32"))] fn budget_for(memory: u64) -> usize {- usize::try_from(memory / 8).unwrap_or(usize::MAX).min(IMAGE_CACHE_MAX)+ usize::try_from(memory / 4).unwrap_or(usize::MAX).min(usize::MAX / 4) } /// Installed memory in bytes (`MemTotal` in `/proc/meminfo`).@@ -359,11 +360,11 @@ mod tests { } #[test]- #[cfg(not(target_arch = "wasm32"))]- fn default_budget_is_an_eighth_of_installed_memory_at_most_1_gib() {- assert_eq!(budget_for(4 << 30), 512 << 20);- assert_eq!(budget_for(8 << 30), IMAGE_CACHE_MAX);- assert_eq!(budget_for(64 << 30), IMAGE_CACHE_MAX);+ #[cfg(target_pointer_width = "64")]+ fn default_budget_is_a_quarter_of_installed_memory() {+ assert_eq!(budget_for(16 << 30), 4 << 30);+ assert_eq!(budget_for(64 << 30), 16 << 30, "no fixed ceiling");+ assert_eq!(budget_for(2 << 30), 512 << 20); } #[test]@@ -372,6 +373,18 @@ mod tests { assert!(physical_memory().is_some_and(|m| m >= 256 << 20), "{:?}", physical_memory()); } + #[test]+ #[cfg(not(target_arch = "wasm32"))]+ fn two_images_of_a_tenth_of_memory_each_stay_cached() {+ // 16 MiB installed (16 GiB scaled down): two images of 1,600 KiB (640 × 640 pixels) take+ // about a fifth of it.+ let mut s = ImageStore::new(budget_for(16 << 20));+ drop(s.insert(key("a"), Arc::new(Pixmap::new(640, 640))));+ drop(s.insert(key("b"), Arc::new(Pixmap::new(640, 640))));+ assert!(s.peek(&key("a")).is_some() && s.peek(&key("b")).is_some(), "neither image is decoded again");+ assert_eq!(s.bytes(), 2 * 640 * 640 * 4);+ }+ #[test] fn sysctl_prints_the_memory_size_in_bytes() { assert_eq!(sysctl_bytes(b"17179869184\n"), Some(16 << 30));@@ -991,6 +991,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Performance:** 20k shapes + 1k texts render in 27 ms per full-retina frame (7.8 ms zoomed), 7× faster than the first version. The UI thread never blocks. The web build is 7.1 MB gzipped. Print-size images (more than 512 MB decoded, up to 2 GB) draw in the canvas and in raster exports and can be trimmed with Crop Image; an image with a side past 65,535 px is shrunk to fit, a raster export says when an image could not be decoded, and Crop Image's trim leaves CMYK images alone (#1517). On Windows `vectorcraft-cli perf` reports the cores busy and, with `--deep`, its working set, and warns on a busy machine as it does on macOS and Linux (#1502). An image whose pixels can't be decoded, such as a PNG cut short or an image over the 2 GB decoding allowance as RGBA that can't be drawn at reduced size, is tried once: the renderer notes it and does not try to decode it again on later frames. An image refused only because the images being drawn leave no room for it is tried again on the next render. On the canvas such an image draws as a light gray box crossed from corner to corner, and the status bar says once for each image that it couldn't be decoded; exports leave it out and report it as before. A PNG, JPEG, GIF or WebP image that takes more than 2 GiB as RGBA (512 MiB in the web app) draws in the canvas and in raster exports at the largest size within that allowance, instead of as that crossed box on the canvas and not at all in exports. Each pixel of the result is the mean of the image's pixels it covers, and the document keeps the whole file. A PNG that isn't interlaced is read a row at a time, and other images are read whole when their decoded samples fit in the allowance. A 16-bit PNG that isn't interlaced, whose decoded samples take more than the allowance and whose RGBA fits in it, draws at its own size, read a row at a time. An image of more pixels than the allowance has bytes (on the desktop, 46,341 × 46,341 is more) still draws as the crossed box, and so does one whose decoded samples take more than the allowance, other than a PNG that isn't interlaced. Open, Place and the Links panel say "an image of W × H pixels is shown at reduced size", and say "too large to draw" of an image that is not drawn at reduced size.+ The renderers keep the decoded images they share within a quarter of the installed memory on Windows, macOS, Linux and FreeBSD, within 1 GiB where the installed memory can't be read, and within 256 MiB in the web build; while the decoded images add up to less than that budget, they are not decoded again when the view changes. With `--deep`, each memory row of `vectorcraft-cli perf` also gives the peak so far: the peak working set on Windows and the peak resident memory (`VmHWM`) on Linux. A new last row gives the memory after the SVG export and the save → open → save at the end of the run. The renderer composes the two ink planes of a CMYK document that shows transparency into screen colors on up to as many threads as it rasterizes with, instead of on one. At 2880 × 1800 on 8 threads, a page of 300 shapes at 20% to 90% opacity takes 30 ms a frame instead of 55 ms, and 50,000 paths with one at 99% opacity take 258 ms instead of 361 ms (`vectorcraft-cli bench`), with the same pixels. With Overprint Preview or Separations Preview on, the renderer keeps the art it prepared for the preview from one frame to the next. It prepares again the objects that changed, and all of the art when Discard White Overprint changes or, with Separations Preview, when the plates shown, the proof setup, the swatches, the Spot Colors option or the color settings change or a profile is loaded. It draws the other objects from the art, geometry and stroke outlines it kept for them.