Skip to main content

euv_core/app/prewarm/
struct.rs

1use super::*;
2
3/// Context signature binding pre-warmed route artifacts to resource version, theme, and display DPR.
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}
16
17/// Bounded speculative task queued to pre-warm a target route without competing with foreground frames.
18#[derive(Clone, Data, Debug, Default, PartialEq)]
19pub struct RoutePrewarmTask {
20    /// Target route identifier (e.g. `"/details/42"`).
21    pub(crate) route_key: String,
22    /// Pre-warm phase kind (`TextShaping`, `GlyphRaster`, `ImageDecode`, `PipelineWarmup`).
23    #[get(type(copy))]
24    pub(crate) kind: PrewarmWorkKind,
25    /// Context key `(version, theme, DPR)` this task was scheduled against.
26    #[get(type(copy))]
27    pub(crate) context: PrewarmContextKey,
28    /// Estimated memory/upload footprint in bytes.
29    #[get(type(copy))]
30    pub(crate) estimated_bytes: usize,
31    /// Estimated execution duration in microseconds for budgeted frame slicing.
32    #[get(type(copy))]
33    pub(crate) estimated_us: u64,
34    /// Lower values execute earlier (`0` = highest pre-warm priority).
35    #[get(type(copy))]
36    pub(crate) priority: u8,
37}
38
39/// Completed route pre-warm artifact retained under bounded memory until consumed or invalidated.
40#[derive(Clone, Data, Debug, Default, PartialEq)]
41pub struct PrewarmedRouteArtifact {
42    /// Target route identifier.
43    pub(crate) route_key: String,
44    /// Exact `(version, theme, DPR)` context key matching this artifact.
45    #[get(type(copy))]
46    pub(crate) context: PrewarmContextKey,
47    /// Bitmask of completed `PrewarmWorkKind` phases (`1 << (kind as u8)`).
48    #[get(type(copy))]
49    pub(crate) completed_work_mask: u8,
50    /// Aggregate tracked bytes held by this artifact.
51    #[get(type(copy))]
52    pub(crate) resident_bytes: usize,
53    /// Number of completed pre-warm tasks folded into this artifact.
54    #[get(type(copy))]
55    pub(crate) prepared_items: usize,
56}
57
58/// Bounded, cancellable, context-validated route pre-warming pipeline.
59#[derive(Clone, Data, Debug)]
60pub struct RoutePrewarmer {
61    /// Maximum pending tasks allowed in the bounded queue.
62    #[get(type(copy))]
63    pub(crate) max_pending_tasks: usize,
64    /// Maximum aggregate resident bytes held across all ready artifacts.
65    #[get(type(copy))]
66    pub(crate) max_memory_bytes: usize,
67    /// Maximum bytes processed/uploaded per budgeted frame slice.
68    #[get(type(copy))]
69    pub(crate) max_upload_bytes_per_frame: usize,
70    /// Default time slice budget in microseconds per frame.
71    #[get(type(copy))]
72    pub(crate) default_step_budget_us: u64,
73    /// Active context `(version, theme, DPR)` governing queue validity.
74    #[get(type(copy))]
75    pub(crate) active_context: PrewarmContextKey,
76    /// Whether speculative pre-warming is enabled (paused automatically under memory pressure).
77    #[get(type(copy))]
78    pub(crate) enabled: bool,
79    /// Bounded queue of pending pre-warm tasks ordered by priority.
80    pub(crate) pending: Vec<RoutePrewarmTask>,
81    /// Ready pre-warmed route artifacts awaiting consumption on navigation.
82    pub(crate) ready: Vec<PrewarmedRouteArtifact>,
83    /// Current aggregate resident bytes across `ready`.
84    #[get(type(copy))]
85    #[get_mut(skip)]
86    #[set(skip)]
87    pub(crate) resident_bytes: usize,
88    /// Cumulative accepted pre-warm tasks.
89    #[get(type(copy))]
90    #[get_mut(skip)]
91    #[set(skip)]
92    pub(crate) enqueued_count: u64,
93    /// Cumulative pre-warm tasks completed inside frame budgets.
94    #[get(type(copy))]
95    #[get_mut(skip)]
96    #[set(skip)]
97    pub(crate) executed_tasks: u64,
98    /// Cumulative pre-warm tasks cancelled via route cancellation, context drift, or memory pressure.
99    #[get(type(copy))]
100    #[get_mut(skip)]
101    #[set(skip)]
102    pub(crate) cancelled_tasks: u64,
103    /// Cumulative ready artifacts discarded due to version/theme/DPR invalidation or budget eviction.
104    #[get(type(copy))]
105    #[get_mut(skip)]
106    #[set(skip)]
107    pub(crate) invalidated_artifacts: u64,
108    /// Cumulative tasks deferred because the per-frame time or upload budget was reached.
109    #[get(type(copy))]
110    #[get_mut(skip)]
111    #[set(skip)]
112    pub(crate) budget_deferrals: u64,
113}