dev/perf-vm-allocation-and-copy-pressure #18
@ -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)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user