mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Preferences: Effect Cache accepts only the budget the web honours
Review follow-up (CodeRabbit on #10921): - The Effect Cache field's range (prefs::range, which bounds both the dialog and prefs.set) tops out at the web cap of 1536 MB in the web build, so the dialog no longer shows and saves a value the cache never gets. Desktop keeps 16..65536. - The byte budget moves into effect_cache_budget_bytes_for(stored, web), so the web cap is tested on every target, not only when tests run as wasm32 (CI only type-checks wasm). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
41e675e35d
commit
d8003129ec
3 files changed
+46
-9
No files matched your search
@@ -578,6 +578,18 @@ fn honoured_memory_usage_mb(stored: u32, web: bool) -> u32 {
|
||||
if web { stored.min(WASM_MEMORY_USAGE_CAP_MB) } else { stored }
|
||||
}
|
||||
|
||||
/// The largest Effect Cache the Preferences dialog and `prefs.set` accept, in MB: the web build's
|
||||
/// cap there, so the field shows the budget the cache really gets.
|
||||
fn effect_cache_max_mb(web: bool) -> u32 {
|
||||
if web { WASM_MEMORY_USAGE_CAP_MB } else { 65536 }
|
||||
}
|
||||
|
||||
/// The layer-effect cache budget a build honours for a `stored` preference, in bytes: capped on
|
||||
/// the web build (`web`), and saturating rather than wrapping a 32-bit `usize`.
|
||||
fn effect_cache_budget_bytes_for(stored: u32, web: bool) -> usize {
|
||||
(honoured_memory_usage_mb(stored, web) as usize).saturating_mul(1 << 20)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
pub struct Performance {
|
||||
@@ -670,7 +682,7 @@ impl Performance {
|
||||
/// The layer-effect cache budget the build honours, in bytes: [`Performance::effect_cache_mb`],
|
||||
/// capped on the web like Memory Usage.
|
||||
pub fn effect_cache_budget_bytes(&self) -> usize {
|
||||
(honoured_memory_usage_mb(self.effect_cache_mb, cfg!(target_arch = "wasm32")) as usize).saturating_mul(1 << 20)
|
||||
effect_cache_budget_bytes_for(self.effect_cache_mb, cfg!(target_arch = "wasm32"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1083,14 +1083,39 @@ fn the_web_build_caps_memory_usage() {
|
||||
}
|
||||
|
||||
/// The effect cache budget is the stored MB in bytes, capped on the web like Memory Usage, and
|
||||
/// never wraps: on wasm32 an uncapped 4096 MB shifted into `usize` was 0.
|
||||
/// never wraps: on wasm32 an uncapped 4096 MB shifted into `usize` was 0. Both builds are checked
|
||||
/// on every target.
|
||||
#[test]
|
||||
fn the_effect_cache_budget_is_capped_on_the_web_and_never_wraps() {
|
||||
let web = cfg!(target_arch = "wasm32");
|
||||
for stored in [16, 768, WASM_MEMORY_USAGE_CAP_MB + 1, 4096, 65536, u32::MAX] {
|
||||
let p = Performance { effect_cache_mb: stored, ..Performance::default() };
|
||||
let mb = if web { stored.min(WASM_MEMORY_USAGE_CAP_MB) } else { stored };
|
||||
assert_eq!(p.effect_cache_budget_bytes(), (mb as usize).saturating_mul(1 << 20), "{stored} MB");
|
||||
assert!(p.effect_cache_budget_bytes() >= 16 << 20, "{stored} MB");
|
||||
const MB: usize = 1 << 20;
|
||||
for (stored, web_mb) in [
|
||||
(16, 16),
|
||||
(768, 768),
|
||||
(WASM_MEMORY_USAGE_CAP_MB, WASM_MEMORY_USAGE_CAP_MB),
|
||||
(WASM_MEMORY_USAGE_CAP_MB + 1, WASM_MEMORY_USAGE_CAP_MB),
|
||||
(4096, WASM_MEMORY_USAGE_CAP_MB),
|
||||
(u32::MAX, WASM_MEMORY_USAGE_CAP_MB),
|
||||
] {
|
||||
assert_eq!(effect_cache_budget_bytes_for(stored, true), web_mb as usize * MB, "web, {stored} MB");
|
||||
assert_eq!(effect_cache_budget_bytes_for(stored, false), (stored as usize).saturating_mul(MB), "desktop, {stored} MB");
|
||||
}
|
||||
let p = Performance { effect_cache_mb: 4096, ..Performance::default() };
|
||||
assert_eq!(p.effect_cache_budget_bytes(), effect_cache_budget_bytes_for(4096, cfg!(target_arch = "wasm32")));
|
||||
}
|
||||
|
||||
/// The Effect Cache field accepts only what the build honours: up to the web cap on the web, so
|
||||
/// the dialog never shows a value the cache doesn't get.
|
||||
#[test]
|
||||
fn the_effect_cache_range_matches_the_honoured_budget() {
|
||||
assert_eq!(effect_cache_max_mb(true), WASM_MEMORY_USAGE_CAP_MB);
|
||||
assert_eq!(effect_cache_max_mb(false), 65536);
|
||||
for web in [true, false] {
|
||||
let max = effect_cache_max_mb(web);
|
||||
assert_eq!(effect_cache_budget_bytes_for(max, web), max as usize * (1 << 20), "web = {web}: the largest accepted value is honoured in full");
|
||||
}
|
||||
let web = cfg!(target_arch = "wasm32");
|
||||
assert_eq!(range("performance.effectCacheMb"), Some((16.0, f64::from(effect_cache_max_mb(web)))));
|
||||
assert!(check_value("performance.effectCacheMb", &json!(effect_cache_max_mb(web))).is_ok());
|
||||
assert!(check_value("performance.effectCacheMb", &json!(effect_cache_max_mb(web) + 1)).is_err());
|
||||
assert!(u64::from(Performance::default().effect_cache_mb) <= u64::from(effect_cache_max_mb(true)), "the default fits the web cap");
|
||||
}
|
||||
@@ -122,7 +122,7 @@ pub fn range(path: &str) -> Option<(f64, f64)> {
|
||||
"performance.historyStates" => (1.0, 1000.0),
|
||||
"performance.cacheLevels" => (1.0, 8.0),
|
||||
"performance.cacheTileSize" => (256.0, 16384.0),
|
||||
"performance.effectCacheMb" => (16.0, 65536.0),
|
||||
"performance.effectCacheMb" => (16.0, f64::from(super::effect_cache_max_mb(cfg!(target_arch = "wasm32")))),
|
||||
"transparencyAndGamut.gamutWarningOpacity" => (1.0, 100.0),
|
||||
"unitsAndRulers.columnWidth" | "unitsAndRulers.gutter" => (0.0, 10_000.0),
|
||||
"unitsAndRulers.printResolution" | "unitsAndRulers.screenResolution" | "rawDefaults.resolution" => (1.0, 10_000.0),
|
||||
|
||||
Reference in new issue
Block a user