euv-performance 0.48.1

Reproducible CPU, layout, rasterization, and allocation benchmarks for the cross-platform euv runtime.
Documentation
use super::*;

/// Per-iteration latency percentile distribution, frame-budget misses, allocation counters, and layout/damage telemetry.
#[derive(Clone, Copy, Debug, Default, Deserialize, Getter, PartialEq, Serialize)]
pub struct LatencyDistribution {
    /// Number of measured iterations included in this distribution.
    #[get(type(copy))]
    pub(crate) iterations: usize,
    /// Median (50th percentile) per-iteration latency in microseconds.
    #[get(type(copy))]
    pub(crate) p50_us: f64,
    /// 95th percentile per-iteration latency in microseconds.
    #[get(type(copy))]
    pub(crate) p95_us: f64,
    /// 99th percentile per-iteration latency in microseconds.
    #[get(type(copy))]
    pub(crate) p99_us: f64,
    /// 99.9th percentile per-iteration latency in microseconds.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) p99_9_us: f64,
    /// Maximum single-iteration latency in microseconds.
    #[get(type(copy))]
    pub(crate) max_us: f64,
    /// Arithmetic mean per-iteration latency in microseconds.
    #[get(type(copy))]
    pub(crate) mean_us: f64,
    /// Sample standard deviation (frame-time jitter) in microseconds.
    #[get(type(copy))]
    pub(crate) jitter_us: f64,
    /// Number of iterations exceeding the 480Hz frame budget (`2.083ms`).
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) over_2_08ms_count: usize,
    /// Number of iterations exceeding the 360Hz frame budget (`2.778ms`).
    #[get(type(copy))]
    pub(crate) over_2_78ms_count: usize,
    /// Number of iterations exceeding the 240Hz frame budget (`4.167ms`).
    #[get(type(copy))]
    pub(crate) over_4_17ms_count: usize,
    /// Number of iterations exceeding the 144Hz frame budget (`6.94ms`).
    #[get(type(copy))]
    pub(crate) over_6_94ms_count: usize,
    /// Number of iterations exceeding the 60Hz frame budget (`16.67ms`).
    #[get(type(copy))]
    pub(crate) over_16_67ms_count: usize,
    /// Percentage of measured frames exceeding the 240Hz (`4.167ms`) budget.
    #[get(type(copy))]
    pub(crate) missed_240hz_pct: f64,
    /// Percentage of measured frames exceeding the 360Hz (`2.778ms`) budget.
    #[get(type(copy))]
    pub(crate) missed_360hz_pct: f64,
    /// Percentage of measured frames exceeding the 480Hz (`2.083ms`) budget.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) missed_480hz_pct: f64,
    /// Effective sustained throughput in frames per second (`1_000_000 / mean_us`).
    #[get(type(copy))]
    pub(crate) effective_fps: f64,
    /// Arithmetic mean `FrameTelemetry::dirty_area_ratio` across measured frames (`0.0` when not applicable).
    #[get(type(copy))]
    pub(crate) mean_dirty_area_ratio: f64,
    /// Count of measured frames that promoted to full-viewport redraw (`FullRedrawReason != None`).
    #[get(type(copy))]
    pub(crate) full_redraw_count: usize,
    /// Total heap allocations recorded across all measured steady-state frames.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) alloc_count_total: u64,
    /// Total heap deallocations recorded across all measured steady-state frames.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) free_count_total: u64,
    /// Total heap bytes allocated across all measured steady-state frames.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) bytes_allocated_total: u64,
    /// Arithmetic mean heap allocations per measured frame.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) mean_allocs_per_frame: f64,
    /// Arithmetic mean heap bytes allocated per measured frame.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) mean_bytes_per_frame: f64,
    /// Maximum single-frame heap allocation count observed.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) max_allocs_per_frame: u64,
    /// Maximum single-frame heap bytes allocated observed.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) max_bytes_per_frame: u64,
    /// Peak positive net live heap bytes observed during the measured window.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) peak_live_bytes: u64,
    /// Measured layout invalidation delta during this scenario window.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) layout_invalidations: u64,
    /// Measured executed layout passes during this scenario window.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) layout_passes: u64,
    /// Measured layout passes that mutated node geometry during this scenario window.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) layout_changed_passes: u64,
    /// Measured total scene nodes whose final layout geometry changed during this window.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) layout_changed_nodes_total: u64,
    /// Measured total display-list draw commands recorded during this scenario window.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) draw_commands_total: u64,
    /// Measured total physical pixels shaded during this scenario window.
    #[get(type(copy))]
    #[serde(default)]
    pub(crate) pixels_shaded_total: u64,
}

/// Pre-allocated per-scenario telemetry accumulator avoiding measurement-induced heap allocations.
#[derive(Clone, Debug, Default)]
pub(crate) struct FrameMeasureAccum {
    /// Raw per-iteration elapsed durations in microseconds.
    pub(crate) samples_us: Vec<f64>,
    /// Per-frame `dirty_area_ratio` samples.
    pub(crate) dirty_ratios: Vec<f32>,
    /// Count of measured frames that promoted to full-viewport redraw.
    pub(crate) full_redraw_count: usize,
    /// Cumulative heap allocation count across all measured frames.
    pub(crate) alloc_count_total: u64,
    /// Cumulative heap free count across all measured frames.
    pub(crate) free_count_total: u64,
    /// Cumulative heap bytes allocated across all measured frames.
    pub(crate) bytes_allocated_total: u64,
    /// Peak single-frame heap allocation count.
    pub(crate) max_allocs_per_frame: u64,
    /// Peak single-frame heap bytes allocated.
    pub(crate) max_bytes_per_frame: u64,
    /// Peak net live heap bytes observed during the measured window.
    pub(crate) peak_live_bytes: u64,
    /// Measured layout invalidations delta across the window.
    pub(crate) layout_invalidations: u64,
    /// Measured layout passes delta across the window.
    pub(crate) layout_passes: u64,
    /// Measured layout changed passes delta across the window.
    pub(crate) layout_changed_passes: u64,
    /// Measured layout changed nodes total delta across the window.
    pub(crate) layout_changed_nodes_total: u64,
    /// Cumulative display-list draw commands recorded across the window.
    pub(crate) draw_commands_total: u64,
    /// Cumulative physical pixels shaded across the window.
    pub(crate) pixels_shaded_total: u64,
}

/// Per-step result captured from one leaf row mutation inside the A/B partial-damage benchmark.
#[derive(Clone, Copy, Debug)]
pub(crate) struct RowMutationStep {
    /// Elapsed `App::step_frame` wall latency in microseconds.
    pub(crate) elapsed_us: f64,
    /// Deterministic rendered framebuffer hash.
    pub(crate) frame_hash: u64,
    /// Per-frame damage, paint, and layout telemetry snapshot.
    pub(crate) telemetry: FrameTelemetry,
    /// Exact heap allocation delta observed during `step_frame`.
    pub(crate) alloc_delta: AllocationSnapshot,
}

/// Single scenario entry recorded inside a `StressMatrixReport`.
#[derive(Clone, Debug, Deserialize, Getter, New, PartialEq, Serialize)]
pub struct StressMatrixEntry {
    /// Canonical stress scenario identifier.
    pub(crate) name: String,
    /// Recorded per-iteration latency distribution and frame-budget telemetry.
    #[get(type(copy))]
    pub(crate) latency: LatencyDistribution,
    /// Human-readable verification metadata and scenario invariants.
    pub(crate) detail: String,
}

/// Interleaved A/B comparison validating P1 surgical partial-layout damage against full redraw.
#[derive(Clone, Debug, Deserialize, Getter, PartialEq, Serialize)]
pub struct PartialDamageAbSummary {
    /// Canonical A/B scenario identifier.
    pub(crate) name: String,
    /// Distribution captured with `app.set_partial_layout_damage(false)`.
    #[get(type(copy))]
    pub(crate) baseline_full_redraw: LatencyDistribution,
    /// Distribution captured with `app.set_partial_layout_damage(true)`.
    #[get(type(copy))]
    pub(crate) candidate_partial_damage: LatencyDistribution,
    /// Percentage latency reduction at p50 (`> 0.0` means partial damage is faster).
    #[get(type(copy))]
    pub(crate) p50_speedup_pct: f64,
    /// Percentage latency reduction at p95 (`> 0.0` means partial damage is faster).
    #[get(type(copy))]
    pub(crate) p95_speedup_pct: f64,
    /// Percentage latency reduction at p99 (`> 0.0` means partial damage is faster).
    #[get(type(copy))]
    pub(crate) p99_speedup_pct: f64,
    /// Percentage reduction in mean `dirty_area_ratio` from full redraw to surgical partial damage.
    #[get(type(copy))]
    pub(crate) dirty_area_ratio_drop_pct: f64,
    /// `true` when every single measured frame produced bit-exact RGBA framebuffer parity.
    #[get(type(copy))]
    pub(crate) bit_exact_parity: bool,
    /// Number of interleaved A/B frames verified for hash parity.
    #[get(type(copy))]
    pub(crate) verified_steps: usize,
    /// Concise summary of resolution, parity, and dirty-area telemetry.
    pub(crate) detail: String,
}

/// Complete serialized report produced by `run_stress_matrix` / `run_filtered_stress_matrix`.
#[derive(Clone, Debug, Deserialize, Getter, New, PartialEq, Serialize)]
pub struct StressMatrixReport {
    /// Ordered stress scenario results.
    pub(crate) entries: Vec<StressMatrixEntry>,
    /// Optional structured interleaved A/B partial-layout damage comparison when that scenario ran.
    #[get(skip)]
    pub(crate) partial_damage_ab: Option<PartialDamageAbSummary>,
    /// Optional stage-attributed cold-start TTFF benchmark breakdown when that scenario ran.
    #[get(skip)]
    #[new(skip)]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub(crate) cold_start_ttff: Option<ColdStartTtffReport>,
}

/// Deterministic 2D arcade benchmark scene decoupling 60Hz fixed physics from 240Hz/480Hz interpolated rendering.
#[derive(Clone, Data, Debug)]
pub(crate) struct BenchGame2dScene {
    /// Generational ECS entity arena.
    pub(crate) world: GameWorld,
    /// Spatial-hash 2D rigid-body physics solver.
    pub(crate) physics: PhysicsWorld2D,
    /// Zero-allocation pooled particle emitter.
    pub(crate) particles: ParticleSystem,
    /// Frustum-culled arena tilemap.
    pub(crate) tilemap: TileMap,
    /// Follow camera tracking the arena player.
    #[get(type(copy))]
    pub(crate) camera: Camera2D,
    /// Immutable double-buffered world snapshots for render-time interpolation.
    pub(crate) snapshots: DoubleBufferedSnapshot<World2DSnapshot>,
    /// Active player entity identifier.
    #[get(type(copy))]
    pub(crate) player_id: EntityId,
    /// Cumulative fixed simulation ticks executed.
    #[get(type(copy))]
    pub(crate) fixed_steps: u64,
    /// Cumulative interpolated visual frames rendered.
    #[get(type(copy))]
    pub(crate) rendered_frames: u64,
    /// Persistent scratch buffer formatting HUD text without per-frame allocations.
    pub(crate) hud_text_buf: String,
}

/// Deterministic 3D GPU direct-composite benchmark scene decoupling 60Hz simulation from 240Hz/480Hz HUD+GPU compositing.
#[derive(Clone, Data, Debug)]
pub(crate) struct BenchGame3dGpuScene {
    /// Open-world 3D city simulation state.
    pub(crate) world: World3D,
    /// Action map driving deterministic vehicle motion.
    pub(crate) actions: ActionMap,
    /// Double-buffered 3D simulation snapshots for interpolated presentation.
    pub(crate) snapshots: DoubleBufferedSnapshot<World3DSnapshot>,
    /// Shared same-device GPU render target descriptor for zero-readback compositing.
    pub(crate) gpu_target: GpuCompositeTarget,
    /// Monotonic GPU submission fence counter.
    #[get(type(copy))]
    pub(crate) frame_fence: u64,
    /// Cumulative fixed simulation ticks executed.
    #[get(type(copy))]
    pub(crate) fixed_steps: u64,
    /// Cumulative interpolated visual frames rendered.
    #[get(type(copy))]
    pub(crate) rendered_frames: u64,
    /// Persistent scratch buffer formatting HUD text without per-frame allocations.
    pub(crate) hud_text_buf: String,
}