Size default slide buffers from available physical RAM

This commit is contained in:
Dandaedre 2026-11-20 07:16:46 +01:00
parent 8e2a6d663f
commit a0be4211b8
11 changed files with 127 additions and 14 deletions

48
Cargo.lock generated
View File

@ -1799,6 +1799,15 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
[[package]]
name = "ntapi"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3b335231dfd352ffb0f8017f3b6027a4917f7df785ea2143d8af2adc66980ae"
dependencies = [
"winapi",
]
[[package]]
name = "num-traits"
version = "0.2.19"
@ -2212,7 +2221,7 @@ dependencies = [
[[package]]
name = "pdf-presenter"
version = "0.1.45"
version = "0.1.46"
dependencies = [
"bytemuck",
"chrono",
@ -2231,6 +2240,7 @@ dependencies = [
"sha2",
"softbuffer",
"sys-locale",
"sysinfo",
"tempfile",
"toml 0.8.23",
"wayland-client",
@ -3004,6 +3014,20 @@ dependencies = [
"libc",
]
[[package]]
name = "sysinfo"
version = "0.39.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2071df9448915b71c4fe6d25deaf1c22f12bd234f01540b77312bb8e41361e6"
dependencies = [
"libc",
"memchr",
"ntapi",
"objc2-core-foundation",
"objc2-io-kit",
"windows",
]
[[package]]
name = "tempfile"
version = "3.27.0"
@ -3605,6 +3629,22 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.11"
@ -3614,6 +3654,12 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.62.2"

View File

@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"]
resolver = "3"
[workspace.package]
version = "0.1.45"
version = "0.1.46"
edition = "2024"
license = "MIT"
repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter"

View File

@ -26,6 +26,7 @@ image = { version = "=0.25.10", default-features = false, features = ["png", "jp
hayro = "=0.9.0"
chrono = "0.4"
rfd = "=0.15.4"
sysinfo = { version = "=0.39.6", default-features = false, features = ["system"] }
[target.'cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))'.dependencies]
keepawake = "=0.6.1"

View File

@ -860,7 +860,7 @@ impl App {
if host.cache.contains_key(&info.path) {
continue;
}
let limit = host.state.buffer_mib.max(256) as usize * 1024 * 1024;
let limit = host.state.buffer_mib.max(64) as usize * 1024 * 1024;
if make_output_room(
&mut host.cache,
host.frame.as_ref(),

View File

@ -1418,7 +1418,7 @@ fn menu(ui: &mut Ui, s: &mut Studio) {
if ui.checkbox(&mut s.settings.auto_show,tr(&locale,"Show presentation automatically when opening a document")).changed() {s.save_preferences();}
ui.separator();
ui.label(tr(&locale,"RAM budget per process (presenter + output each use this allowance):"));
if ui.add(egui::Slider::new(&mut s.settings.buffer_mib,256..=16384).text("MiB")).changed() {s.remember_buffer_budget();}
if ui.add(egui::Slider::new(&mut s.settings.buffer_mib,64..=16384).text("MiB")).changed() {s.remember_buffer_budget();}
ui.small(tr(&locale,"Raise only within available RAM; OS paging can cause delays. Screen rendering is capped at 4096 px."));
ui.separator();
ui.label(s.preparation_status());

View File

@ -191,6 +191,30 @@ pub struct Settings {
pub theme: crate::theme::Theme,
pub language: crate::localization::Language,
}
/// Choose a per-process decoded-frame budget from available physical RAM.
/// Prefer 15%, with a soft 512 MiB floor that never exceeds 20% (except the
/// 64 MiB operational minimum). Unknown memory uses a conservative 256 MiB.
pub fn buffer_budget_mib(available_bytes: Option<u64>) -> u32 {
let Some(bytes) = available_bytes else {
return 256;
};
let mib = bytes / (1024 * 1024);
(mib.saturating_mul(15) / 100)
.max(512)
.min(mib / 5)
.clamp(64, 16384) as u32
}
fn default_buffer_mib() -> u32 {
// Probe only RAM, once per process: no process enumeration or UI polling.
static BUDGET: std::sync::OnceLock<u32> = std::sync::OnceLock::new();
*BUDGET.get_or_init(|| {
let mut system = sysinfo::System::new();
system.refresh_memory_specifics(sysinfo::MemoryRefreshKind::nothing().with_ram());
buffer_budget_mib((system.total_memory() > 0).then(|| system.available_memory()))
})
}
impl Default for Settings {
fn default() -> Self {
Self {
@ -203,7 +227,7 @@ impl Default for Settings {
presentation_fullscreen: true,
browser_monitor: None,
thumbnail_size: 220.,
buffer_mib: 1024,
buffer_mib: default_buffer_mib(),
auto_show: true,
theme: Default::default(),
language: Default::default(),
@ -215,8 +239,8 @@ impl Settings {
if self.version != 1 {
return Err(format!("Unsupported settings version {}", self.version));
}
if !(256..=16384).contains(&self.buffer_mib) {
return Err("RAM buffer must be 256–16384 MiB per process".into());
if !(64..=16384).contains(&self.buffer_mib) {
return Err("RAM buffer must be 64–16384 MiB per process".into());
}
if self.projects.len() > 4096 || !(100. ..=400.).contains(&self.thumbnail_size) {
return Err("Invalid settings limits".into());

View File

@ -45,7 +45,7 @@ fn settings_reject_invalid_versions_ranges_and_duplicate_roles() {
};
assert!(s.validate().is_err());
s.version = 1;
s.buffer_mib = 128;
s.buffer_mib = 63;
assert!(s.validate().is_err());
s.buffer_mib = 1024;
s.layout.clock.size = f32::NAN;
@ -66,7 +66,10 @@ fn settings_reject_invalid_versions_ranges_and_duplicate_roles() {
assert!(settings::read(&p).unwrap().layout.header);
assert!(!settings::read(&p).unwrap().layout.previous.show);
assert!(!Layout::default().previous.show);
assert_eq!(settings::read(&p).unwrap().buffer_mib, 1024);
assert_eq!(
settings::read(&p).unwrap().buffer_mib,
Settings::default().buffer_mib
);
assert!(settings::read(&p).unwrap().auto_show);
}
#[test]
@ -163,3 +166,27 @@ fn slide_colors_migrate_roundtrip_and_reject_invalid_channels() {
);
}
}
#[test]
fn automatic_buffer_budget_softens_floor_under_memory_pressure() {
let budget = |mib: u64| settings::buffer_budget_mib(Some(mib * 1024 * 1024));
assert_eq!(budget(8192), 1228); // 15% on a roomy system.
assert_eq!(budget(3072), 512); // Soft floor, still below 20%.
assert_eq!(budget(2048), 409); // Floor yields to memory pressure.
assert_eq!(budget(1024), 204);
assert_eq!(budget(256), 64);
assert_eq!(budget(0), 64);
assert_eq!(budget(1024 * 1024), 16384);
assert_eq!(settings::buffer_budget_mib(None), 256);
assert_eq!(settings::buffer_budget_mib(Some(u64::MAX)), 16384);
let legacy: Settings = toml::from_str("version=1\nbuffer_mib=1024").unwrap();
assert_eq!(legacy.buffer_mib, 1024); // Explicit saved budgets remain authoritative.
for value in [64, 204, 512, 16384] {
Settings {
buffer_mib: value,
..Default::default()
}
.validate()
.unwrap();
}
}

View File

@ -2,6 +2,12 @@
## Unreleased
### 0.1.46
- Choose unsaved RAM budgets from 15% of available memory, with a soft 512 MiB
floor limited to 20% and a 64 MiB operational minimum for constrained systems.
Preserve explicit saved budgets and apply the lower limit to both processes.
### 0.1.45
- Distinguish Theme and Language section headings with smaller, bold, muted text

View File

@ -42,8 +42,10 @@ usage, approximate ETA and memory-pressure pause are explicit in the presenter.
No application slide-file reads, decoding or rasterization occur on prepared navigation.
OS paging can still occur; configuring enough available physical RAM remains necessary.
The default decoded budget is 1024 MiB per process, adjustable in Menu. Insufficient
capacity pauses rather than evicts and never reports READY. Worker/texture memory is
The default decoded budget is 15% of available RAM per process, with a soft
512 MiB floor constrained to 20% of available RAM (64–16384 MiB operational bounds),
adjustable in Menu. Insufficient capacity uses rolling eviction of non-active slides
and never reports the entire deck as RAM-ready. Worker/texture memory is
additional. See [cache](../interfaces/extraction-cache.md),
[settings](../interfaces/settings.md) and [private IPC](../interfaces/process-protocol.md).

View File

@ -55,9 +55,14 @@ flushed temporary file. Unknown fields are ignored and not preserved on round tr
- `presenter_fullscreen`, `presentation_fullscreen`: booleans, default true.
- `browser_monitor`: optional monitor ID; missing/unavailable means presenter screen.
- `thumbnail_size`: logical width in pixels, finite 100–400; default 220.
- `buffer_mib`: integer 256–16384, default 1024, added in 0.1.13. Decoded slide RAM
- `buffer_mib`: integer 64–16384, adaptive default, added in 0.1.13. Decoded slide RAM
allowance for each presenter/output process; one MiB = 1048576 bytes. Additional
worker/texture/UI memory is not included. Older v1 files default to 1024. The menu
worker/texture/UI memory is not included. Since 0.1.46, missing budgets use 15% of available physical RAM measured once at
process startup, raised toward 512 MiB only within a 20% ceiling. The operational
minimum is 64 MiB, maximum 16384 MiB; failed memory detection uses 256 MiB.
Explicit saved budgets (including the old 1024 MiB default) remain unchanged.
Saving preferences persists the chosen numeric budget; it is not continuously
retuned. Older binaries reject budgets below their former 256 MiB minimum. The menu
persists changes asynchronously. Since 0.1.19, lowering evicts non-active frames
while reserving room for outstanding renders; increasing allows RAM refill.

View File

@ -149,7 +149,9 @@ decoding. Raster composition still happens, and the OS can page memory under pre
The entire deck stays resident when it fits the configured RAM budget.
Menu → Preferences → RAM budget controls the decoded-slide allowance for **each process**, default
1024 MiB, configurable from 256 to 16384 MiB. Presenter and output can each consume
15% of available RAM, with a soft 512 MiB minimum that yields when it would
exceed 20% of available RAM. The adjustable range is 64–16384 MiB. Saved budgets
are preserved; the automatic default is chosen when no budget has been saved. Presenter and output can each consume
that allowance; textures, workers and other application memory are additional.
Preparation reserves capacity for in-flight frames. When the deck cannot fit, the
**Rolling buffer** frees distant slides and continues preparing the remaining pages.