From e672e4d6b625100f6b8a92c422b94b9aea5b93f4 Mon Sep 17 00:00:00 2001 From: bQUARKz Date: Fri, 10 Apr 2026 09:20:07 +0100 Subject: [PATCH] [PERF] Runtime Telemetry Hot Path --- crates/console/prometeu-drivers/src/asset.rs | 32 +++++++++++++------ .../prometeu-hal/src/log/log_service.rs | 7 +--- crates/console/prometeu-hal/src/telemetry.rs | 5 +-- .../src/virtual_machine_runtime/tick.rs | 3 +- crates/console/prometeu-vm/src/heap.rs | 2 +- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/crates/console/prometeu-drivers/src/asset.rs b/crates/console/prometeu-drivers/src/asset.rs index ac0f1169..b7f6b2bb 100644 --- a/crates/console/prometeu-drivers/src/asset.rs +++ b/crates/console/prometeu-drivers/src/asset.rs @@ -17,10 +17,17 @@ use std::sync::{Arc, Mutex, RwLock}; use std::thread; use std::time::Instant; +type ResidentMap = HashMap>; +type StagedValue = (Arc, usize); +type StagingMap = HashMap>; + +type AssetTable = HashMap; +type HandleTable = HashMap; + const GLYPH_BANK_PALETTE_COUNT_V1: usize = 64; const GLYPH_BANK_COLORS_PER_PALETTE: usize = 16; const GLYPH_BANK_PALETTE_BYTES_V1: usize = - GLYPH_BANK_PALETTE_COUNT_V1 * GLYPH_BANK_COLORS_PER_PALETTE * std::mem::size_of::(); + GLYPH_BANK_PALETTE_COUNT_V1 * GLYPH_BANK_COLORS_PER_PALETTE * size_of::(); /// Resident metadata for a decoded/materialized asset inside a BankPolicy. #[derive(Debug)] @@ -54,10 +61,10 @@ impl ResidentEntry { /// This is internal to the AssetManager and not visible to peripherals. pub struct BankPolicy { /// Dedup table: asset_id -> resident entry (value + telemetry). - pub resident: Arc>>>, + pub resident: Arc>>, /// Staging area: handle -> value ready to commit. - pub staging: Arc, usize)>>>, + pub staging: Arc>>, /// Total bytes currently in resident storage. pub used_bytes: Arc, @@ -119,7 +126,7 @@ impl BankPolicy { } /// Take staged value (used by commit path). - pub fn take_staging(&self, handle: HandleId) -> Option<(Arc, usize)> { + pub fn take_staging(&self, handle: HandleId) -> Option> { let entry = self.staging.write().unwrap().remove(&handle); if let Some((_, bytes)) = entry.as_ref() { self.inflight_bytes.fetch_sub(*bytes, Ordering::Relaxed); @@ -136,8 +143,8 @@ impl BankPolicy { } pub struct AssetManager { - assets: Arc>>, - handles: Arc>>, + assets: Arc>, + handles: Arc>, next_handle_id: Mutex, assets_data: Arc>, @@ -476,7 +483,11 @@ impl AssetManager { bank_arc, entry_clone.decoded_size as usize, ); - gfx_policy.stage(handle_id, resident_arc, entry_clone.decoded_size as usize); + gfx_policy.stage( + handle_id, + resident_arc, + entry_clone.decoded_size as usize, + ); let mut handles_map = handles.write().unwrap(); if let Some(h) = handles_map.get_mut(&handle_id) { @@ -500,8 +511,11 @@ impl AssetManager { bank_arc, entry_clone.decoded_size as usize, ); - sound_policy - .stage(handle_id, resident_arc, entry_clone.decoded_size as usize); + sound_policy.stage( + handle_id, + resident_arc, + entry_clone.decoded_size as usize, + ); let mut handles_map = handles.write().unwrap(); if let Some(h) = handles_map.get_mut(&handle_id) { diff --git a/crates/console/prometeu-hal/src/log/log_service.rs b/crates/console/prometeu-hal/src/log/log_service.rs index e6d991e6..b5620f65 100644 --- a/crates/console/prometeu-hal/src/log/log_service.rs +++ b/crates/console/prometeu-hal/src/log/log_service.rs @@ -10,12 +10,7 @@ pub struct LogService { impl LogService { pub fn new(capacity: usize) -> Self { - Self { - events: VecDeque::with_capacity(capacity), - capacity, - next_seq: 0, - logs_count: 0, - } + Self { events: VecDeque::with_capacity(capacity), capacity, next_seq: 0, logs_count: 0 } } pub fn log( diff --git a/crates/console/prometeu-hal/src/telemetry.rs b/crates/console/prometeu-hal/src/telemetry.rs index 361cf11c..c061e98d 100644 --- a/crates/console/prometeu-hal/src/telemetry.rs +++ b/crates/console/prometeu-hal/src/telemetry.rs @@ -180,10 +180,7 @@ impl Certifier { LogLevel::Warn, LogSource::Pos, 0xCA07, - format!( - "Cert: Log pressure exceeded limit ({} > {})", - telemetry.logs_count, limit - ), + format!("Cert: Log pressure exceeded limit ({} > {})", telemetry.logs_count, limit), ); violations += 1; } diff --git a/crates/console/prometeu-system/src/virtual_machine_runtime/tick.rs b/crates/console/prometeu-system/src/virtual_machine_runtime/tick.rs index 9168fae8..a879f514 100644 --- a/crates/console/prometeu-system/src/virtual_machine_runtime/tick.rs +++ b/crates/console/prometeu-system/src/virtual_machine_runtime/tick.rs @@ -149,7 +149,8 @@ impl VirtualMachineRuntime { self.telemetry_current.logs_count = self.log_service.logs_count; self.log_service.reset_count(); - self.telemetry_current.host_cpu_time_us = start.elapsed().as_micros() as u64; + self.telemetry_current.host_cpu_time_us = + start.elapsed().as_micros() as u64; let ts_ms = self.boot_time.elapsed().as_millis() as u64; self.telemetry_current.violations = self.certifier.evaluate( diff --git a/crates/console/prometeu-vm/src/heap.rs b/crates/console/prometeu-vm/src/heap.rs index bcd4f2dd..0b3d3463 100644 --- a/crates/console/prometeu-vm/src/heap.rs +++ b/crates/console/prometeu-vm/src/heap.rs @@ -2,8 +2,8 @@ use crate::call_frame::CallFrame; use crate::object::{ObjectHeader, ObjectKind}; use prometeu_bytecode::{HeapRef, Value}; -use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicUsize, Ordering}; /// Internal stored object: header plus opaque payload bytes. #[derive(Debug, Clone)]