[PERF] VM Allocation and Copy Pressure

This commit is contained in:
bQUARKz 2026-04-20 09:02:00 +01:00
parent 762f60e00f
commit 8937963819
Signed by: bquarkz
SSH Key Fingerprint: SHA256:Z7dgqoglWwoK6j6u4QC87OveEq74WOhFN+gitsxtkf8

View File

@ -1,10 +1,12 @@
use serde::{Deserialize, Serialize};
use std::cell::Cell;
use std::cmp::Ordering;
use std::fmt::Write;
use std::sync::atomic::{AtomicU64, Ordering as AtomicOrdering};
use std::sync::Arc;
static STRING_MATERIALIZATION_COUNT: AtomicU64 = AtomicU64::new(0);
thread_local! {
static STRING_MATERIALIZATION_COUNT: Cell<u64> = const { Cell::new(0) };
}
/// Opaque handle that references an object stored in the VM heap.
///
@ -83,7 +85,7 @@ impl Value {
where
S: Into<Arc<str>>,
{
STRING_MATERIALIZATION_COUNT.fetch_add(1, AtomicOrdering::Relaxed);
STRING_MATERIALIZATION_COUNT.with(|count| count.set(count.get() + 1));
Value::String(value.into())
}
@ -149,7 +151,7 @@ impl Value {
}
pub fn string_materialization_count() -> u64 {
STRING_MATERIALIZATION_COUNT.load(AtomicOrdering::Relaxed)
STRING_MATERIALIZATION_COUNT.with(Cell::get)
}
#[cfg(test)]