[PERF] Runtime Telemetry Hot Path
This commit is contained in:
@@ -17,10 +17,17 @@ use std::sync::{Arc, Mutex, RwLock};
|
||||
use std::thread;
|
||||
use std::time::Instant;
|
||||
|
||||
type ResidentMap<T> = HashMap<AssetId, ResidentEntry<T>>;
|
||||
type StagedValue<T> = (Arc<T>, usize);
|
||||
type StagingMap<T> = HashMap<HandleId, StagedValue<T>>;
|
||||
|
||||
type AssetTable = HashMap<AssetId, AssetEntry>;
|
||||
type HandleTable = HashMap<HandleId, LoadHandleInfo>;
|
||||
|
||||
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::<u16>();
|
||||
GLYPH_BANK_PALETTE_COUNT_V1 * GLYPH_BANK_COLORS_PER_PALETTE * size_of::<u16>();
|
||||
|
||||
/// Resident metadata for a decoded/materialized asset inside a BankPolicy.
|
||||
#[derive(Debug)]
|
||||
@@ -54,10 +61,10 @@ impl<T> ResidentEntry<T> {
|
||||
/// This is internal to the AssetManager and not visible to peripherals.
|
||||
pub struct BankPolicy<T> {
|
||||
/// Dedup table: asset_id -> resident entry (value + telemetry).
|
||||
pub resident: Arc<RwLock<HashMap<AssetId, ResidentEntry<T>>>>,
|
||||
pub resident: Arc<RwLock<ResidentMap<T>>>,
|
||||
|
||||
/// Staging area: handle -> value ready to commit.
|
||||
pub staging: Arc<RwLock<HashMap<HandleId, (Arc<T>, usize)>>>,
|
||||
pub staging: Arc<RwLock<StagingMap<T>>>,
|
||||
|
||||
/// Total bytes currently in resident storage.
|
||||
pub used_bytes: Arc<AtomicUsize>,
|
||||
@@ -119,7 +126,7 @@ impl<T> BankPolicy<T> {
|
||||
}
|
||||
|
||||
/// Take staged value (used by commit path).
|
||||
pub fn take_staging(&self, handle: HandleId) -> Option<(Arc<T>, usize)> {
|
||||
pub fn take_staging(&self, handle: HandleId) -> Option<StagedValue<T>> {
|
||||
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<T> BankPolicy<T> {
|
||||
}
|
||||
|
||||
pub struct AssetManager {
|
||||
assets: Arc<RwLock<HashMap<AssetId, AssetEntry>>>,
|
||||
handles: Arc<RwLock<HashMap<HandleId, LoadHandleInfo>>>,
|
||||
assets: Arc<RwLock<AssetTable>>,
|
||||
handles: Arc<RwLock<HandleTable>>,
|
||||
next_handle_id: Mutex<HandleId>,
|
||||
assets_data: Arc<RwLock<AssetsPayloadSource>>,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user