euv_core/app/prewarm/struct.rs
1use super::*;
2
3/// Context signature binding pre-warmed route artifacts to resource version, theme, display DPR, and locale.
4#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
5pub struct PrewarmContextKey {
6 /// Active application/bundle resource version.
7 #[get(type(copy))]
8 pub(crate) resource_version: u64,
9 /// Active light or dark theme mode.
10 #[get(type(copy))]
11 pub(crate) theme_mode: ThemeMode,
12 /// IEEE-754 bits of the active display scale factor.
13 #[get(type(copy))]
14 pub(crate) dpr_bits: u32,
15 /// Deterministic 64-bit hash of the active BCP-47 locale (`0` when locale-agnostic).
16 #[get(type(copy))]
17 pub(crate) locale_hash: u64,
18}
19
20/// Bounded speculative task queued to pre-warm a target route without competing with foreground frames.
21#[derive(Clone, Data, Debug, Default, PartialEq)]
22pub struct RoutePrewarmTask {
23 /// Target route identifier (e.g. `"/details/42"`).
24 pub(crate) route_key: String,
25 /// Pre-warm phase kind (`TextShaping`, `GlyphRaster`, `ImageDecode`, `PipelineWarmup`).
26 #[get(type(copy))]
27 pub(crate) kind: PrewarmWorkKind,
28 /// Context key `(version, theme, DPR, locale)` this task was scheduled against.
29 #[get(type(copy))]
30 pub(crate) context: PrewarmContextKey,
31 /// Estimated memory/upload footprint in bytes.
32 #[get(type(copy))]
33 pub(crate) estimated_bytes: usize,
34 /// Estimated execution duration in microseconds for budgeted frame slicing.
35 #[get(type(copy))]
36 pub(crate) estimated_us: u64,
37 /// Lower values execute earlier (`0` = highest pre-warm priority).
38 #[get(type(copy))]
39 pub(crate) priority: u8,
40 /// Optional representative label text warmed into the font shaping cache during idle pre-warm slices.
41 pub(crate) sample_text: String,
42}
43
44/// Completed route pre-warm artifact retained under bounded memory until consumed or invalidated.
45#[derive(Clone, Data, Debug, Default, PartialEq)]
46pub struct PrewarmedRouteArtifact {
47 /// Target route identifier.
48 pub(crate) route_key: String,
49 /// Exact `(version, theme, DPR)` context key matching this artifact.
50 #[get(type(copy))]
51 pub(crate) context: PrewarmContextKey,
52 /// Bitmask of completed `PrewarmWorkKind` phases (`1 << (kind as u8)`).
53 #[get(type(copy))]
54 pub(crate) completed_work_mask: u8,
55 /// Aggregate tracked bytes held by this artifact.
56 #[get(type(copy))]
57 pub(crate) resident_bytes: usize,
58 /// Number of completed pre-warm tasks folded into this artifact.
59 #[get(type(copy))]
60 pub(crate) prepared_items: usize,
61}
62
63/// Bounded, cancellable, context-validated route pre-warming pipeline.
64#[derive(Clone, Data, Debug)]
65pub struct RoutePrewarmer {
66 /// Maximum pending tasks allowed in the bounded queue.
67 #[get(type(copy))]
68 pub(crate) max_pending_tasks: usize,
69 /// Maximum aggregate resident bytes held across all ready artifacts.
70 #[get(type(copy))]
71 pub(crate) max_memory_bytes: usize,
72 /// Maximum bytes processed/uploaded per budgeted frame slice.
73 #[get(type(copy))]
74 pub(crate) max_upload_bytes_per_frame: usize,
75 /// Default time slice budget in microseconds per frame.
76 #[get(type(copy))]
77 pub(crate) default_step_budget_us: u64,
78 /// Active context `(version, theme, DPR)` governing queue validity.
79 #[get(type(copy))]
80 pub(crate) active_context: PrewarmContextKey,
81 /// Whether speculative pre-warming is enabled (paused automatically under memory pressure).
82 #[get(type(copy))]
83 pub(crate) enabled: bool,
84 /// Bounded queue of pending pre-warm tasks ordered by priority.
85 pub(crate) pending: Vec<RoutePrewarmTask>,
86 /// Ready pre-warmed route artifacts awaiting consumption on navigation.
87 pub(crate) ready: Vec<PrewarmedRouteArtifact>,
88 /// Current aggregate resident bytes across `ready`.
89 #[get(type(copy))]
90 #[get_mut(skip)]
91 #[set(skip)]
92 pub(crate) resident_bytes: usize,
93 /// Cumulative accepted pre-warm tasks.
94 #[get(type(copy))]
95 #[get_mut(skip)]
96 #[set(skip)]
97 pub(crate) enqueued_count: u64,
98 /// Cumulative pre-warm tasks completed inside frame budgets.
99 #[get(type(copy))]
100 #[get_mut(skip)]
101 #[set(skip)]
102 pub(crate) executed_tasks: u64,
103 /// Cumulative pre-warm tasks cancelled via route cancellation, context drift, or memory pressure.
104 #[get(type(copy))]
105 #[get_mut(skip)]
106 #[set(skip)]
107 pub(crate) cancelled_tasks: u64,
108 /// Cumulative ready artifacts discarded due to version/theme/DPR invalidation or budget eviction.
109 #[get(type(copy))]
110 #[get_mut(skip)]
111 #[set(skip)]
112 pub(crate) invalidated_artifacts: u64,
113 /// Cumulative tasks deferred because the per-frame time or upload budget was reached.
114 #[get(type(copy))]
115 #[get_mut(skip)]
116 #[set(skip)]
117 pub(crate) budget_deferrals: u64,
118 /// True when recent user input or navigation preempted speculative pre-warming until the next quiet frame.
119 #[get(type(copy))]
120 #[get_mut(skip)]
121 #[set(skip)]
122 pub(crate) preempted_until_idle: bool,
123 /// Cumulative post-Frame-1 idle pre-warm slices executed without competing against foreground work.
124 #[get(type(copy))]
125 #[get_mut(skip)]
126 #[set(skip)]
127 pub(crate) idle_slices_executed: u64,
128}
129
130/// Non-blocking cross-platform background worker handle committing computed payloads onto the UI thread without stalling frames.
131#[derive(CustomDebug)]
132pub struct BackgroundTask<T> {
133 /// Lock-free readiness flag flipped to `true` once the background worker stores its payload.
134 pub(crate) ready: Arc<AtomicBool>,
135 /// Shared payload slot populated by the background worker (or synchronously on `wasm32`).
136 #[debug(skip)]
137 pub(crate) slot: Arc<Mutex<Option<T>>>,
138}