Index string provenance with metered image and session tables
This commit is contained in:
@@ -18,3 +18,7 @@ fpmath = { version = "=0.1.1", features = ["soft-float"] }
|
||||
|
||||
[dev-dependencies]
|
||||
prometeu-test-support = { path = "../../dev/prometeu-test-support" }
|
||||
|
||||
[[example]]
|
||||
name = "string_provenance_benchmark"
|
||||
required-features = ["resource-diagnostics"]
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
//! Run in release with --features resource-diagnostics; query setup is excluded.
|
||||
#[allow(dead_code)]
|
||||
#[path = "../tests/support/callables.rs"]
|
||||
mod callables;
|
||||
use prometeu_bytecode::model::ConstantPoolEntry;
|
||||
use prometeu_vm::string_provenance_qualification::Fixture;
|
||||
use std::{
|
||||
alloc::{GlobalAlloc, Layout, System},
|
||||
sync::atomic::{AtomicUsize, Ordering},
|
||||
time::Instant,
|
||||
};
|
||||
struct Counting;
|
||||
static ALLOC: AtomicUsize = AtomicUsize::new(0);
|
||||
static REALLOC: AtomicUsize = AtomicUsize::new(0);
|
||||
static FREE: AtomicUsize = AtomicUsize::new(0);
|
||||
unsafe impl GlobalAlloc for Counting {
|
||||
unsafe fn alloc(&self, l: Layout) -> *mut u8 {
|
||||
ALLOC.fetch_add(1, Ordering::Relaxed);
|
||||
unsafe { System.alloc(l) }
|
||||
}
|
||||
unsafe fn dealloc(&self, p: *mut u8, l: Layout) {
|
||||
FREE.fetch_add(1, Ordering::Relaxed);
|
||||
unsafe { System.dealloc(p, l) }
|
||||
}
|
||||
unsafe fn realloc(&self, p: *mut u8, l: Layout, n: usize) -> *mut u8 {
|
||||
REALLOC.fetch_add(1, Ordering::Relaxed);
|
||||
unsafe { System.realloc(p, l, n) }
|
||||
}
|
||||
}
|
||||
#[global_allocator]
|
||||
static GLOBAL: Counting = Counting;
|
||||
fn counts() -> [usize; 3] {
|
||||
[ALLOC.load(Ordering::Relaxed), REALLOC.load(Ordering::Relaxed), FREE.load(Ordering::Relaxed)]
|
||||
}
|
||||
fn main() {
|
||||
for n in [1024, 16384, 65536] {
|
||||
let constants = vec![ConstantPoolEntry::String("same".into()); n];
|
||||
let start = Instant::now();
|
||||
let image = callables::image_constants(
|
||||
&[("RET", callables::sig(&[], &[]), vec![])],
|
||||
vec![],
|
||||
&constants,
|
||||
)
|
||||
.unwrap();
|
||||
let image_ns = start.elapsed().as_nanos();
|
||||
let payload = image.payload_bytes();
|
||||
let before = counts();
|
||||
let start = Instant::now();
|
||||
let mut fixture = Fixture::new(image, n);
|
||||
let creation_ns = start.elapsed().as_nanos();
|
||||
let after = counts();
|
||||
println!(
|
||||
"setup n={n} image_load_ns={image_ns} image_payload_bytes={payload} session_ns={creation_ns} session_allocs={} auxiliary_bytes={} work={:?}",
|
||||
after[0] - before[0],
|
||||
fixture.auxiliary_bytes(),
|
||||
fixture.work()
|
||||
);
|
||||
for name in [
|
||||
"image_hit",
|
||||
"image_miss",
|
||||
"session_hit",
|
||||
"session_miss",
|
||||
"import_hit",
|
||||
"snapshot_mixed",
|
||||
"import_miss",
|
||||
] {
|
||||
let before = counts();
|
||||
let start = Instant::now();
|
||||
for _ in 0..1000 {
|
||||
fixture.run(name);
|
||||
}
|
||||
let ns = start.elapsed().as_nanos();
|
||||
let after = counts();
|
||||
let delta = std::array::from_fn::<_, 3, _>(|i| after[i] - before[i]);
|
||||
if name.ends_with("hit") || name == "image_miss" || name == "session_miss" {
|
||||
assert_eq!(delta, [0; 3]);
|
||||
}
|
||||
println!(
|
||||
"query n={n} name={name} iterations=1000 ns={ns} alloc_realloc_free={delta:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ mod program_image;
|
||||
mod registry_verifier;
|
||||
pub use program_image::{ImageStringLease, ValidatedProgramImage};
|
||||
// Image/session creation and native provenance consume this in step 19.
|
||||
mod string_identity_index;
|
||||
#[allow(dead_code)]
|
||||
mod string_ledger;
|
||||
// Registry-backed consumers are integrated with executable images in PLN-0176.
|
||||
@@ -52,3 +53,6 @@ pub use virtual_machine::{BudgetReport, LogicalFrameEndingReason, VirtualMachine
|
||||
pub use vm_init_error::{LoaderPatchError, VmInitError};
|
||||
|
||||
pub use verifier::VerifierError;
|
||||
|
||||
#[cfg(feature = "resource-diagnostics")]
|
||||
pub use virtual_machine::string_provenance_qualification;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! PBX v1 publication: immutable metadata and shared payload, after bindings
|
||||
//! and bounded whole-program verification. No public unchecked constructor.
|
||||
use crate::string_identity_index::Identity;
|
||||
use crate::{LoaderPatchError, VmInitError};
|
||||
use prometeu_bytecode::isa::core::CoreOpCode as Op;
|
||||
use prometeu_bytecode::load_limits::{
|
||||
@@ -107,8 +108,30 @@ impl ValidatedProgramImage {
|
||||
Some(ImageStringLease { content: content.clone(), domain: self.strings.clone() })
|
||||
}
|
||||
pub fn retains_string(&self, content: &Arc<str>) -> bool {
|
||||
self.lookup_string(content, || {})
|
||||
}
|
||||
fn lookup_string(&self, content: &Arc<str>, mut compare: impl FnMut()) -> bool {
|
||||
let strings = self.strings.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
strings.records.iter().any(|(weak, _)| std::ptr::eq(weak.as_ptr(), Arc::as_ptr(content)))
|
||||
let target = Identity::of(content);
|
||||
let mut low = 0;
|
||||
let mut high = strings.records.len();
|
||||
while low < high {
|
||||
let mid = low + (high - low) / 2;
|
||||
compare();
|
||||
match record_identity(&strings.records[mid]).cmp(&target) {
|
||||
std::cmp::Ordering::Less => low = mid + 1,
|
||||
std::cmp::Ordering::Greater => high = mid,
|
||||
std::cmp::Ordering::Equal => return true,
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "resource-diagnostics"))]
|
||||
pub(crate) fn lookup_work(&self, content: &Arc<str>) -> (bool, usize) {
|
||||
let mut work = 0;
|
||||
let found = self.lookup_string(content, || work += 1);
|
||||
(found, work)
|
||||
}
|
||||
pub fn constant_content(&self) -> (u64, usize) {
|
||||
let mut strings = self.strings.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
@@ -205,6 +228,7 @@ impl ValidatedProgramImage {
|
||||
};
|
||||
values.push(value);
|
||||
}
|
||||
sort_string_records(&mut records, b)?;
|
||||
b.refund(Q::TemporaryBytes, constants_capacity);
|
||||
// Binding no longer needs source declarations. They were validated,
|
||||
// used exactly, and can be released before final payload publication.
|
||||
@@ -256,6 +280,48 @@ impl ValidatedProgramImage {
|
||||
}
|
||||
}
|
||||
|
||||
fn record_identity(record: &(Weak<str>, usize)) -> Identity {
|
||||
Identity { address: record.0.as_ptr() as *const u8 as usize, length: record.1 }
|
||||
}
|
||||
|
||||
// In-place heapsort: every record comparison (four field reads + comparison)
|
||||
// and swap (two record reads + writes) is precharged. No scratch allocation.
|
||||
fn sort_string_records(records: &mut [(Weak<str>, usize)], b: &mut LoadBudget) -> Result<(), E> {
|
||||
fn sift(
|
||||
records: &mut [(Weak<str>, usize)],
|
||||
mut root: usize,
|
||||
end: usize,
|
||||
b: &mut LoadBudget,
|
||||
) -> Result<(), E> {
|
||||
while root < end / 2 {
|
||||
let mut child = root * 2 + 1;
|
||||
if child + 1 < end {
|
||||
b.work(5)?;
|
||||
if record_identity(&records[child]) < record_identity(&records[child + 1]) {
|
||||
child += 1;
|
||||
}
|
||||
}
|
||||
b.work(5)?;
|
||||
if record_identity(&records[root]) >= record_identity(&records[child]) {
|
||||
break;
|
||||
}
|
||||
b.work(4)?;
|
||||
records.swap(root, child);
|
||||
root = child;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
for root in (0..records.len() / 2).rev() {
|
||||
sift(records, root, records.len(), b)?;
|
||||
}
|
||||
for end in (1..records.len()).rev() {
|
||||
b.work(4)?;
|
||||
records.swap(0, end);
|
||||
sift(records, 0, end, b)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn scratch<T>(count: usize, b: &mut LoadBudget) -> Result<Vec<T>, E> {
|
||||
let bytes = count
|
||||
.checked_mul(size_of::<T>())
|
||||
|
||||
@@ -309,3 +309,65 @@ fn sealed_image_load_probe() {
|
||||
elapsed
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn string_identity_binary_search_preserves_constant_order_and_lease_indices() {
|
||||
let constants = (0..1024).map(|i| K::String(format!("owner-{i}"))).collect::<Vec<_>>();
|
||||
let bytes = fixture(&[1, 0], 0, &constants, None, &[]);
|
||||
let image = ValidatedProgramImage::load(&bytes, &mut budget(), caps::NONE).unwrap();
|
||||
for (i, value) in image.constants().iter().enumerate() {
|
||||
let Value::String(text) = value else { panic!() };
|
||||
assert_eq!(&**text, format!("owner-{i}"));
|
||||
let (found, work) = image.lookup_work(text);
|
||||
assert!(found && work <= 11, "binary work={work}");
|
||||
assert!(Arc::ptr_eq(text, image.lease_constant(i).unwrap().content()));
|
||||
assert!(!image.lookup_work(&Arc::from(text.as_ref())).0);
|
||||
}
|
||||
let lease = image.lease_constant(1023).unwrap();
|
||||
drop(image);
|
||||
assert_eq!(lease.retained_content(), (10, 1));
|
||||
let domain = lease.domain.lock().unwrap();
|
||||
assert_eq!(record_identity(&domain.records[0]), Identity::of(lease.content()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn string_heap_sort_precharges_each_comparison_and_swap_without_scratch() {
|
||||
let owners = (0..16).map(|_| Arc::<str>::from("same")).collect::<Vec<_>>();
|
||||
let source = owners.iter().rev().map(|v| (Arc::downgrade(v), v.len())).collect::<Vec<_>>();
|
||||
let mut full = budget();
|
||||
let mut records = source.clone();
|
||||
sort_string_records(&mut records, &mut full).unwrap();
|
||||
assert!(records.windows(2).all(|v| record_identity(&v[0]) < record_identity(&v[1])));
|
||||
assert_eq!(full.used(Q::TemporaryBytes), 0);
|
||||
for limit in 0..full.used(Q::Work) {
|
||||
let mut b = LoadBudget::new(LoadLimits { work: limit, ..Default::default() });
|
||||
let mut records = source.clone();
|
||||
let error = sort_string_records(&mut records, &mut b).unwrap_err();
|
||||
assert_eq!(error.resource, Some(Q::Work));
|
||||
assert!(b.used(Q::Work) <= limit);
|
||||
assert_eq!(b.used(Q::TemporaryBytes), 0);
|
||||
// Failed sort still owns exactly the original Weak identities.
|
||||
records.sort_unstable_by_key(record_identity);
|
||||
let mut expected = source.clone();
|
||||
expected.sort_unstable_by_key(record_identity);
|
||||
assert!(records.iter().zip(&expected).all(|(a, b)| Weak::ptr_eq(&a.0, &b.0)));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn string_sort_exhaustion_rolls_back_sealed_load_domains() {
|
||||
let constants = vec![K::String("same".into()); 2];
|
||||
let bytes = fixture(&[1, 0], 0, &constants, None, &[]);
|
||||
let mut full = budget();
|
||||
ValidatedProgramImage::load(&bytes, &mut full, caps::NONE).unwrap();
|
||||
// Post-sort sharing costs 2 + 2 + 1 work units. Sorting two records
|
||||
// costs 9 or 13 units, depending on their addresses. Removing another
|
||||
// five leaves at most eight: failure is inside sorting for either order.
|
||||
let mut b =
|
||||
LoadBudget::new(LoadLimits { work: full.used(Q::Work) - 5 - 5, ..Default::default() });
|
||||
let error = ValidatedProgramImage::load(&bytes, &mut b, caps::NONE).unwrap_err();
|
||||
assert!(matches!(error,VmInitError::RegistryLoadFailed(e) if e.resource==Some(Q::Work)));
|
||||
for resource in DOMAINS {
|
||||
assert_eq!(b.used(resource), 0, "{resource:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,6 +385,10 @@ impl<T> BudgetVec<T> {
|
||||
let bytes = b.bytes::<T>(capacity, q)?;
|
||||
let mut extra = b.reserve(q, bytes - self.charge.amount)?;
|
||||
let temporary = b.reserve(RuntimeResource::TemporaryBytes, self.charge.amount)?;
|
||||
#[cfg(test)]
|
||||
if FAIL_NEXT_VEC_ALLOCATION.with(|fail| fail.replace(false)) {
|
||||
return Err(b.failure(q, ResourceReason::AllocationFailed, bytes));
|
||||
}
|
||||
let mut candidate = Vec::new();
|
||||
candidate
|
||||
.try_reserve_exact(capacity)
|
||||
@@ -405,6 +409,21 @@ impl<T> BudgetVec<T> {
|
||||
self.charge.absorb(growth.extra);
|
||||
}
|
||||
}
|
||||
/// Rebuild a table with all fallible capacity/coexistence admission completed
|
||||
/// before moving any old entry. The relocation callback must not allocate.
|
||||
pub(crate) fn rebuild_with(
|
||||
&mut self,
|
||||
len: usize,
|
||||
vacant: impl FnMut() -> T,
|
||||
relocate: impl FnOnce(&mut [T], &mut [T]),
|
||||
) -> Result<(), ResourceFailure> {
|
||||
let mut growth = self.prepare_capacity(len.max(self.data.capacity()))?;
|
||||
growth.candidate.resize_with(len, vacant);
|
||||
relocate(&mut self.data, &mut growth.candidate);
|
||||
self.data = growth.candidate;
|
||||
self.charge.absorb(growth.extra);
|
||||
Ok(())
|
||||
}
|
||||
pub fn reserve(&mut self, additional: usize) -> Result<(), ResourceFailure> {
|
||||
let growth = self.prepare_growth(additional)?;
|
||||
self.commit_growth(growth);
|
||||
@@ -445,9 +464,6 @@ impl<T> BudgetVec<T> {
|
||||
pub fn clear(&mut self) {
|
||||
self.data.clear();
|
||||
}
|
||||
pub(crate) fn retain(&mut self, keep: impl FnMut(&T) -> bool) {
|
||||
self.data.retain(keep);
|
||||
}
|
||||
pub(crate) fn extend_from_slice(&mut self, values: &[T]) -> Result<(), ResourceFailure>
|
||||
where
|
||||
T: Clone,
|
||||
@@ -509,3 +525,8 @@ pub(crate) struct VecGrowth<T> {
|
||||
_temporary: Reservation,
|
||||
old_capacity: usize,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
thread_local! {
|
||||
pub(crate) static FAIL_NEXT_VEC_ALLOCATION: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
//! Private allocation identity index. Values retain Weak ownership, never content.
|
||||
use crate::resource_budget::{
|
||||
BudgetVec, ResourceFailure, ResourceReason, RuntimeBudget, RuntimeResource as Q,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub(crate) struct Identity {
|
||||
pub(crate) address: usize,
|
||||
pub(crate) length: usize,
|
||||
}
|
||||
impl Identity {
|
||||
pub(crate) fn of(content: &Arc<str>) -> Self {
|
||||
Self { address: Arc::as_ptr(content) as *const u8 as usize, length: content.len() }
|
||||
}
|
||||
fn hash(self) -> usize {
|
||||
// Mix aligned addresses and lengths; collisions still compare both fields.
|
||||
let mut n = (self.address as u64) ^ (self.length as u64).wrapping_mul(0x9e3779b97f4a7c15);
|
||||
n = (n ^ (n >> 30)).wrapping_mul(0xbf58476d1ce4e5b9);
|
||||
n = (n ^ (n >> 27)).wrapping_mul(0x94d049bb133111eb);
|
||||
(n ^ (n >> 31)) as usize
|
||||
}
|
||||
}
|
||||
#[derive(Debug)]
|
||||
enum Bucket<T> {
|
||||
Empty,
|
||||
Tombstone,
|
||||
Occupied(Identity, T),
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct IdentityIndex<T> {
|
||||
buckets: BudgetVec<Bucket<T>>,
|
||||
live: usize,
|
||||
tombstones: usize,
|
||||
}
|
||||
impl<T> IdentityIndex<T> {
|
||||
pub(crate) fn new(budget: &RuntimeBudget) -> Self {
|
||||
Self { buckets: BudgetVec::new(budget, Q::AuxiliaryBytes), live: 0, tombstones: 0 }
|
||||
}
|
||||
pub(crate) fn len(&self) -> usize {
|
||||
self.live
|
||||
}
|
||||
pub(crate) fn contains(&self, key: Identity, mut probe: impl FnMut()) -> bool {
|
||||
let size = self.buckets.len();
|
||||
if size == 0 {
|
||||
return false;
|
||||
}
|
||||
let mut at = key.hash() & (size - 1);
|
||||
loop {
|
||||
probe();
|
||||
match &self.buckets[at] {
|
||||
Bucket::Empty => return false,
|
||||
Bucket::Occupied(found, _) if *found == key => return true,
|
||||
_ => at = (at + 1) & (size - 1),
|
||||
}
|
||||
}
|
||||
}
|
||||
pub(crate) fn prepare(&mut self, budget: &RuntimeBudget) -> Result<(), ResourceFailure> {
|
||||
let size = self.buckets.len();
|
||||
let next = self.live + 1;
|
||||
let capacity = if size == 0 {
|
||||
8
|
||||
} else if next > size / 2 {
|
||||
size.checked_mul(2).ok_or_else(|| {
|
||||
budget.failure(Q::AuxiliaryBytes, ResourceReason::SizeOverflow, u64::MAX)
|
||||
})?
|
||||
} else if next + self.tombstones > size / 2 {
|
||||
size
|
||||
} else {
|
||||
return Ok(());
|
||||
};
|
||||
self.buckets.rebuild_with(
|
||||
capacity,
|
||||
|| Bucket::Empty,
|
||||
|old, new| {
|
||||
for slot in old {
|
||||
if let Bucket::Occupied(key, value) = std::mem::replace(slot, Bucket::Empty) {
|
||||
Self::place(new, key, value);
|
||||
}
|
||||
}
|
||||
},
|
||||
)?;
|
||||
self.tombstones = 0;
|
||||
Ok(())
|
||||
}
|
||||
fn place(buckets: &mut [Bucket<T>], key: Identity, value: T) -> bool {
|
||||
let mut at = key.hash() & (buckets.len() - 1);
|
||||
loop {
|
||||
match &buckets[at] {
|
||||
Bucket::Empty | Bucket::Tombstone => {
|
||||
let reused = matches!(buckets[at], Bucket::Tombstone);
|
||||
buckets[at] = Bucket::Occupied(key, value);
|
||||
return reused;
|
||||
}
|
||||
Bucket::Occupied(found, _) => {
|
||||
assert_ne!(*found, key, "duplicate allocation identity")
|
||||
}
|
||||
}
|
||||
at = (at + 1) & (buckets.len() - 1);
|
||||
}
|
||||
}
|
||||
pub(crate) fn insert(&mut self, key: Identity, value: T) {
|
||||
assert!(self.live < self.buckets.len() / 2, "prepare must precede publication");
|
||||
if Self::place(&mut self.buckets, key, value) {
|
||||
self.tombstones -= 1;
|
||||
}
|
||||
self.live += 1;
|
||||
}
|
||||
pub(crate) fn retain(&mut self, mut keep: impl FnMut(&T) -> bool) {
|
||||
for slot in &mut *self.buckets {
|
||||
if matches!(slot, Bucket::Occupied(_, value) if !keep(value)) {
|
||||
// Erase the key before releasing the Weak/reservations. Its
|
||||
// allocation address cannot be recycled while Weak survives.
|
||||
let removed = std::mem::replace(slot, Bucket::Tombstone);
|
||||
self.live -= 1;
|
||||
self.tombstones += 1;
|
||||
drop(removed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -0,0 +1,72 @@
|
||||
use super::*;
|
||||
#[test]
|
||||
fn collision_chains_distinguish_full_identity_and_survive_tombstones() {
|
||||
let b = RuntimeBudget::default();
|
||||
let mut table = IdentityIndex::new(&b);
|
||||
let keys: Vec<_> = (0..1000)
|
||||
.map(|address| Identity { address, length: 4 })
|
||||
.filter(|k| k.hash() & 7 == 0)
|
||||
.take(4)
|
||||
.collect();
|
||||
for (i, key) in keys.iter().enumerate() {
|
||||
table.prepare(&b).unwrap();
|
||||
table.insert(*key, i);
|
||||
}
|
||||
for key in &keys {
|
||||
assert!(table.contains(*key, || {}));
|
||||
}
|
||||
table.retain(|i| *i != 1);
|
||||
assert!(!table.contains(keys[1], || {}));
|
||||
assert!(table.contains(keys[3], || {}));
|
||||
assert!(!table.contains(Identity { length: 5, ..keys[3] }, || {}));
|
||||
table.prepare(&b).unwrap(); // Rebuild removes tombstones at half occupancy.
|
||||
table.insert(keys[1], 1);
|
||||
assert_eq!(table.len(), 4);
|
||||
assert_eq!(table.tombstones, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tombstone_reuse_keeps_collision_successors_and_length_is_part_of_key() {
|
||||
let b = RuntimeBudget::default();
|
||||
let mut t = IdentityIndex::new(&b);
|
||||
let key = Identity { address: 16, length: 0 };
|
||||
t.prepare(&b).unwrap();
|
||||
t.insert(key, 1);
|
||||
t.prepare(&b).unwrap();
|
||||
t.insert(Identity { length: 1, ..key }, 2);
|
||||
t.retain(|v| *v != 1);
|
||||
assert_eq!(t.tombstones, 1);
|
||||
t.prepare(&b).unwrap();
|
||||
t.insert(key, 3);
|
||||
assert_eq!(t.tombstones, 0);
|
||||
assert!(t.contains(key, || {}));
|
||||
assert!(t.contains(Identity { length: 1, ..key }, || {}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn controlled_probe_counts_and_half_load_survive_growth_and_rebuild() {
|
||||
let b = RuntimeBudget::default();
|
||||
let mut table = IdentityIndex::new(&b);
|
||||
for n in 0..1024 {
|
||||
table.prepare(&b).unwrap();
|
||||
table.insert(Identity { address: n * 16, length: n % 7 }, n);
|
||||
assert!(table.live * 2 <= table.buckets.len());
|
||||
}
|
||||
let mut max_probes = 0;
|
||||
for n in 0..2048 {
|
||||
let mut probes = 0;
|
||||
assert_eq!(
|
||||
table.contains(Identity { address: n * 16, length: n % 7 }, || probes += 1),
|
||||
n < 1024
|
||||
);
|
||||
max_probes = max_probes.max(probes);
|
||||
}
|
||||
// A reproducible synthetic-key bound for this fixture, not a hash-table
|
||||
// worst-case claim or a constraint on allocator-selected real addresses.
|
||||
assert!(max_probes <= 32, "fixture probes={max_probes}");
|
||||
table.retain(|n| n % 2 == 0);
|
||||
table.prepare(&b).unwrap();
|
||||
for n in 0..1024 {
|
||||
assert_eq!(table.contains(Identity { address: n * 16, length: n % 7 }, || {}), n % 2 == 0);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
use crate::resource_budget::{
|
||||
BudgetVec, Reservation, ResourceFailure, ResourceReason, RuntimeBudget, RuntimeResource as Q,
|
||||
};
|
||||
use crate::string_identity_index::{Identity, IdentityIndex};
|
||||
use prometeu_bytecode::Value;
|
||||
use std::sync::{Arc, Mutex, MutexGuard, Weak};
|
||||
|
||||
@@ -17,7 +18,7 @@ struct Entry {
|
||||
#[derive(Debug)]
|
||||
struct Domain {
|
||||
budget: RuntimeBudget,
|
||||
entries: BudgetVec<Entry>,
|
||||
entries: IdentityIndex<Entry>,
|
||||
_state: Reservation,
|
||||
}
|
||||
|
||||
@@ -49,7 +50,7 @@ impl StringLedger {
|
||||
Q::AuxiliaryBytes,
|
||||
budget.bytes::<Mutex<Domain>>(1, Q::AuxiliaryBytes)? + 2 * size_of::<usize>() as u64,
|
||||
)?;
|
||||
let entries = BudgetVec::new(&budget, Q::AuxiliaryBytes);
|
||||
let entries = IdentityIndex::new(&budget);
|
||||
Ok(Self(Arc::new(Mutex::new(Domain { budget, entries, _state: state }))))
|
||||
}
|
||||
fn domain(&self) -> MutexGuard<'_, Domain> {
|
||||
@@ -57,7 +58,7 @@ impl StringLedger {
|
||||
}
|
||||
|
||||
/// Safepoint reconciliation is bounded by the accepted allocation count.
|
||||
/// Retain compacts in place; unused capacity remains charged until drop.
|
||||
/// Dead buckets become tombstones; retained capacity stays charged until drop.
|
||||
pub(crate) fn reconcile(&self) -> usize {
|
||||
self.domain().reconcile()
|
||||
}
|
||||
@@ -65,9 +66,19 @@ impl StringLedger {
|
||||
self.domain().entries.len()
|
||||
}
|
||||
pub(crate) fn retains(&self, content: &Arc<str>) -> bool {
|
||||
let address = Arc::as_ptr(content);
|
||||
self.domain().entries.iter().any(|entry| std::ptr::eq(entry.content.as_ptr(), address))
|
||||
self.lookup(content, || {})
|
||||
}
|
||||
fn lookup(&self, content: &Arc<str>, mut probe: impl FnMut()) -> bool {
|
||||
self.domain().entries.contains(Identity::of(content), &mut probe)
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "resource-diagnostics"))]
|
||||
pub(crate) fn lookup_work(&self, content: &Arc<str>) -> (bool, usize) {
|
||||
let mut work = 0;
|
||||
let found = self.lookup(content, || work += 1);
|
||||
(found, work)
|
||||
}
|
||||
|
||||
pub(crate) fn lease(&self, content: &Arc<str>) -> Option<StringLease> {
|
||||
self.retains(content)
|
||||
.then(|| StringLease { content: content.clone(), domain: self.clone() })
|
||||
@@ -239,23 +250,24 @@ impl Domain {
|
||||
}
|
||||
Err(failure) => return Err(failure),
|
||||
};
|
||||
if let Err(failure) = self.entries.reserve(1) {
|
||||
if let Err(failure) = self.entries.prepare(&self.budget) {
|
||||
if failure.reason != ResourceReason::Limit {
|
||||
return Err(failure);
|
||||
}
|
||||
self.reconcile();
|
||||
self.entries.reserve(1)?;
|
||||
self.entries.prepare(&self.budget)?;
|
||||
}
|
||||
Ok(charges)
|
||||
}
|
||||
fn publish(&mut self, content: &Arc<str>, charges: Charges) {
|
||||
self.entries
|
||||
.push(Entry {
|
||||
self.entries.insert(
|
||||
Identity::of(content),
|
||||
Entry {
|
||||
content: Arc::downgrade(content),
|
||||
_bytes: charges.bytes,
|
||||
_allocation: charges.allocation,
|
||||
})
|
||||
.expect("prepare reserved one ledger record before materialization");
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -259,3 +259,95 @@ fn formatting_refuses_result_and_temporary_limits_with_no_content_publication()
|
||||
assert_eq!(budget.used(Q::StringAllocations), 0);
|
||||
assert_eq!(ledger.tracked_allocations(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn index_growth_refuses_auxiliary_temporary_and_allocator_before_materialization() {
|
||||
for failure in [0, 1, 2] {
|
||||
let (budget, ledger) = fixture(&[]);
|
||||
let kept = (0..4).map(|_| ledger.import("kept").unwrap()).collect::<Vec<_>>();
|
||||
let auxiliary = budget.used(Q::AuxiliaryBytes);
|
||||
match failure {
|
||||
0 => budget.test_lower_limit(Q::AuxiliaryBytes, auxiliary),
|
||||
1 => budget.test_lower_limit(Q::TemporaryBytes, 0),
|
||||
_ => crate::resource_budget::FAIL_NEXT_VEC_ALLOCATION.with(|fail| fail.set(true)),
|
||||
}
|
||||
let mut called = false;
|
||||
let result = ledger.build(4, &mut |w| {
|
||||
called = true;
|
||||
w.write_str("next")
|
||||
});
|
||||
let Err(MaterializeError::Resource(error)) = result else {
|
||||
panic!("expected prepublication refusal")
|
||||
};
|
||||
assert!(!called);
|
||||
assert_eq!(
|
||||
error.resource,
|
||||
if failure == 1 { Q::TemporaryBytes } else { Q::AuxiliaryBytes }
|
||||
);
|
||||
assert_eq!(
|
||||
error.reason,
|
||||
if failure == 2 { ResourceReason::AllocationFailed } else { ResourceReason::Limit }
|
||||
);
|
||||
assert_eq!(ledger.tracked_allocations(), 4);
|
||||
assert_eq!(budget.used(Q::StringBytes), 16);
|
||||
assert_eq!(budget.used(Q::StringAllocations), 4);
|
||||
assert_eq!(budget.used(Q::AuxiliaryBytes), auxiliary);
|
||||
assert_eq!(budget.used(Q::TemporaryBytes), 0);
|
||||
for value in &kept {
|
||||
assert!(ledger.retains(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn index_initial_allocation_failure_and_rebuild_failure_refund_reservations() {
|
||||
let (budget, ledger) = fixture(&[]);
|
||||
let initial = budget.used(Q::AuxiliaryBytes);
|
||||
crate::resource_budget::FAIL_NEXT_VEC_ALLOCATION.with(|fail| fail.set(true));
|
||||
assert_eq!(ledger.import("x").unwrap_err().reason, ResourceReason::AllocationFailed);
|
||||
assert_eq!(ledger.tracked_allocations(), 0);
|
||||
assert_eq!(budget.used(Q::AuxiliaryBytes), initial);
|
||||
assert_eq!(budget.used(Q::StringBytes), 0);
|
||||
assert_eq!(budget.used(Q::StringAllocations), 0);
|
||||
let mut kept = (0..4).map(|_| ledger.import("same").unwrap()).collect::<Vec<_>>();
|
||||
let old = Arc::downgrade(&kept.pop().unwrap());
|
||||
assert_eq!(ledger.reconcile(), 1);
|
||||
let auxiliary = budget.used(Q::AuxiliaryBytes);
|
||||
budget.test_lower_limit(Q::TemporaryBytes, 0);
|
||||
assert_eq!(ledger.import("new").unwrap_err().resource, Q::TemporaryBytes);
|
||||
assert_eq!(ledger.tracked_allocations(), 3);
|
||||
assert_eq!(budget.used(Q::AuxiliaryBytes), auxiliary);
|
||||
assert_eq!(budget.used(Q::TemporaryBytes), 0);
|
||||
assert_eq!(budget.used(Q::StringBytes), 12);
|
||||
for value in &kept {
|
||||
assert_eq!(Arc::strong_count(value), 1);
|
||||
assert!(ledger.retains(value));
|
||||
}
|
||||
assert!(old.upgrade().is_none());
|
||||
// Rebuild under a restored test budget; no production ceiling changes.
|
||||
budget.test_lower_limit(Q::TemporaryBytes, 64 * 1024 * 1024);
|
||||
let newer = ledger.import("same").unwrap();
|
||||
assert!(ledger.retains(&newer));
|
||||
assert!(!ledger.retains(&Arc::from("same")));
|
||||
assert!(ledger.lookup_work(&newer).0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tombstone_rebuild_allocator_refusal_preserves_live_keys_and_charges() {
|
||||
let (budget, ledger) = fixture(&[]);
|
||||
let mut owners = (0..4).map(|_| ledger.import("same").unwrap()).collect::<Vec<_>>();
|
||||
owners.pop();
|
||||
assert_eq!(ledger.reconcile(), 1);
|
||||
let auxiliary = budget.used(Q::AuxiliaryBytes);
|
||||
crate::resource_budget::FAIL_NEXT_VEC_ALLOCATION.with(|fail| fail.set(true));
|
||||
assert_eq!(ledger.import("new").unwrap_err().reason, ResourceReason::AllocationFailed);
|
||||
assert_eq!(ledger.tracked_allocations(), 3);
|
||||
assert_eq!(budget.used(Q::StringBytes), 12);
|
||||
assert_eq!(budget.used(Q::StringAllocations), 3);
|
||||
assert_eq!(budget.used(Q::AuxiliaryBytes), auxiliary);
|
||||
assert_eq!(budget.used(Q::TemporaryBytes), 0);
|
||||
assert!(owners.iter().all(|v| ledger.retains(v)));
|
||||
let new = ledger.import("new").unwrap();
|
||||
assert!(ledger.retains(&new));
|
||||
assert_eq!(budget.used(Q::AuxiliaryBytes), auxiliary);
|
||||
}
|
||||
|
||||
@@ -3890,3 +3890,6 @@ mod tests {
|
||||
#[cfg(test)]
|
||||
#[path = "virtual_machine/callable_tests.rs"]
|
||||
mod callable_tests;
|
||||
|
||||
#[cfg(feature = "resource-diagnostics")]
|
||||
pub mod string_provenance_qualification;
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
//! Opt-in diagnostics for the actual native provenance boundaries.
|
||||
use super::*;
|
||||
use crate::ValidatedProgramImage;
|
||||
use std::{hint::black_box, sync::Arc};
|
||||
|
||||
pub struct Fixture {
|
||||
vm: VirtualMachine,
|
||||
owners: Vec<Arc<str>>,
|
||||
image_hit: Arc<str>,
|
||||
miss: Arc<str>,
|
||||
}
|
||||
impl Fixture {
|
||||
pub fn new(image: Arc<ValidatedProgramImage>, count: usize) -> Self {
|
||||
let Value::String(image_hit) = image.constants().last().unwrap() else { panic!() };
|
||||
let image_hit = image_hit.clone();
|
||||
let mut vm = VirtualMachine::from_image(image, Default::default());
|
||||
let ledger = crate::string_ledger::StringLedger::new(vm.budget.clone()).unwrap();
|
||||
let owners = (0..count).map(|_| ledger.import("same").unwrap()).collect::<Vec<_>>();
|
||||
vm.strings = Some(ledger);
|
||||
vm.operand_stack.push(Value::String(image_hit.clone())).unwrap();
|
||||
vm.operand_stack.push(Value::String(owners.last().unwrap().clone())).unwrap();
|
||||
Self { vm, owners, image_hit, miss: Arc::from("same") }
|
||||
}
|
||||
pub fn auxiliary_bytes(&self) -> u64 {
|
||||
self.vm.budget.used(RuntimeResource::AuxiliaryBytes)
|
||||
}
|
||||
pub fn work(&self) -> [usize; 4] {
|
||||
let image = self.vm.validated_image.as_ref().unwrap();
|
||||
let session = self.vm.strings.as_ref().unwrap();
|
||||
let (ih, iw) = image.lookup_work(&self.image_hit);
|
||||
let (im, mw) = image.lookup_work(&self.miss);
|
||||
let (sh, sw) = session.lookup_work(self.owners.last().unwrap());
|
||||
let (sm, tw) = session.lookup_work(&self.miss);
|
||||
assert!(ih && sh && !im && !sm);
|
||||
[iw, mw, sw, tw]
|
||||
}
|
||||
pub fn run(&mut self, workload: &str) {
|
||||
match workload {
|
||||
"image_hit" => {
|
||||
black_box(
|
||||
self.vm
|
||||
.validated_image
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.retains_string(black_box(&self.image_hit)),
|
||||
);
|
||||
}
|
||||
"image_miss" => {
|
||||
black_box(
|
||||
self.vm.validated_image.as_ref().unwrap().retains_string(black_box(&self.miss)),
|
||||
);
|
||||
}
|
||||
"session_hit" => {
|
||||
black_box(
|
||||
self.vm
|
||||
.strings
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.retains(black_box(self.owners.last().unwrap())),
|
||||
);
|
||||
}
|
||||
"session_miss" => {
|
||||
black_box(self.vm.strings.as_ref().unwrap().retains(black_box(&self.miss)));
|
||||
}
|
||||
"import_hit" => {
|
||||
black_box(
|
||||
self.vm
|
||||
.import_string_value(&Value::String(self.owners.last().unwrap().clone()))
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
"import_miss" => {
|
||||
black_box(self.vm.import_string_value(&Value::String(self.miss.clone())).unwrap());
|
||||
}
|
||||
"snapshot_mixed" => {
|
||||
black_box(self.vm.operand_stack_top(2));
|
||||
}
|
||||
_ => panic!("unknown workload"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,3 +97,40 @@ fn warmed_instruction_regions_do_not_allocate() {
|
||||
assert_eq!(counts, (0, 0), "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "resource-diagnostics")]
|
||||
#[allow(dead_code)]
|
||||
#[path = "support/callables.rs"]
|
||||
mod provenance_callables;
|
||||
|
||||
#[cfg(feature = "resource-diagnostics")]
|
||||
#[test]
|
||||
fn provenance_queries_allocate_nothing_at_all_qualification_sizes() {
|
||||
use prometeu_bytecode::model::ConstantPoolEntry;
|
||||
use prometeu_vm::string_provenance_qualification::Fixture;
|
||||
for count in [1024_usize, 16384, 65536] {
|
||||
let constants = vec![ConstantPoolEntry::String("same".into()); count];
|
||||
let image = provenance_callables::image_constants(
|
||||
&[("RET", provenance_callables::sig(&[], &[]), vec![])],
|
||||
vec![],
|
||||
&constants,
|
||||
)
|
||||
.unwrap();
|
||||
let mut fixture = Fixture::new(image, count);
|
||||
let work = fixture.work();
|
||||
let bound = count.ilog2() as usize + 1;
|
||||
assert!(work[0] <= bound && work[1] <= bound);
|
||||
for workload in ["image_hit", "image_miss", "session_hit", "session_miss", "import_hit"] {
|
||||
COUNTS.with(|c| c.set(Some((0, 0))));
|
||||
for _ in 0..100 {
|
||||
fixture.run(workload);
|
||||
}
|
||||
let counts = COUNTS.with(|c| c.replace(None)).unwrap();
|
||||
assert_eq!(counts, (0, 0), "{workload}, owners={count}");
|
||||
}
|
||||
COUNTS.with(|c| c.set(Some((0, 0))));
|
||||
fixture.run("snapshot_mixed");
|
||||
let counts = COUNTS.with(|c| c.replace(None)).unwrap();
|
||||
assert_eq!(counts, (1, 1), "only snapshot Value storage allocates");
|
||||
}
|
||||
}
|
||||
|
||||
+30
@@ -109,6 +109,36 @@ AGD-0055's future plan. It does not approve that agenda's proposal, weaken the
|
||||
final PBX contract or label transferred code as executed. Other agendas retain
|
||||
their own collection/string/stress/game obligations.
|
||||
|
||||
## Index ownership identity without owning content
|
||||
|
||||
Provenance is an allocation-identity question, not an equality-of-text question.
|
||||
The image index sorts the existing Weak records by address and length during
|
||||
sealed loading. The session index uses a half-full open-addressed table. Both
|
||||
preserve Arc values and explicit native leases, so ordinary string reads remain
|
||||
direct and accounting does not keep content alive strongly.
|
||||
|
||||
The allocation lifetime matters as much as the key. A Weak prevents the allocator
|
||||
from recycling an address while its record remains indexed. Remove the key before
|
||||
dropping that Weak. Tombstones preserve collision chains, and a metered rebuild
|
||||
removes them without losing live identities. Admit the new capacity and its
|
||||
coexistence with old storage before moving entries or constructing new strings;
|
||||
failed admission must leave live owners recognizable and unpublished charges
|
||||
refunded.
|
||||
|
||||
The [release qualification](../../../docs/vm-arch/string-provenance-qualification.md)
|
||||
measured the existing linear boundary queries before changing them. At 65,536
|
||||
owners the indexed image took 16–17 comparisons and the session fixtures took
|
||||
1–2 probes, with no lookup allocation. The tradeoff is explicit: session metadata
|
||||
rose from about 4 MiB to 10 MiB and setup became more expensive under the same
|
||||
quotas. This is boundary-work evidence, not a claim of faster game frames.
|
||||
Synthetic collision keys and work-limit tests complement real-address timings;
|
||||
allocator-selected address order is not a stable test oracle across loads.
|
||||
|
||||
This implementation follows [DEC-0065](../../workflow/decisions/DEC-0065-q8-index-string-provenance-within-existing-quotas.md).
|
||||
The [published ownership contract](../../../docs/specs/runtime/02c-program-registry-and-pbx-v1.md#memory-ownership-and-quotas)
|
||||
remains normative; native import, snapshot retention and typed storage tests
|
||||
verify the same owner lifetimes through the new indices.
|
||||
|
||||
## Takeaways
|
||||
|
||||
- Keep each plan atomic to its originating agenda and identify integration ownership before execution.
|
||||
|
||||
@@ -234,6 +234,23 @@ Image constants and session-created strings are separate accounting domains; cha
|
||||
|
||||
Each domain tracks UTF-8 bytes and allocation count using a bounded Weak<str> ledger without a strong accounting owner. Reads remain direct Arc accesses, not handle-table lookups. Reconcile dead entries at safepoints and before quota refusal, release Weak plus charge then; Weak may retain native allocation after last strong drop, so no immediate-release promise. Keep accounting domains alive while tracked allocations survive, including host/tool retention. Import untracked native strings as charged new allocations; explicit session transfer copies into the destination domain, while shared-image constants remain shared.
|
||||
|
||||
Provenance keys include both allocation data address and UTF-8 length. Image
|
||||
Weak records are sorted once during sealed loading by a bounded in-place heap
|
||||
sort, with record comparisons/reads/writes charged before work through LoadBudget;
|
||||
binary search serves native boundary identity queries. This does not reorder
|
||||
constants, exports or lease indices. Record capacities remain part of the
|
||||
existing image payload accounting.
|
||||
|
||||
Session provenance uses a precharged open-addressed BudgetVec table with at most
|
||||
50% live occupancy, geometric growth and explicit tombstones. Charge retained
|
||||
capacity through AuxiliaryBytes and old/new capacity coexistence through
|
||||
TemporaryBytes before rehashing. Reserve content and bucket growth before
|
||||
materialization; refusal must not publish content or an entry and must refund
|
||||
provisional reservations. Remove stale keys before releasing their Weak ownership;
|
||||
reuse tombstones and rebuild under the same capacity accounting. Queries allocate
|
||||
nothing, ordinary reads do not query the index, and resource ceilings and
|
||||
reconciliation safepoints are unchanged.
|
||||
|
||||
Check result sizes/overflow and reserve before materializing; roll back reservations and initialized state on failure. Charge transient buffer/result coexistence. No hidden unmetered concatenation/native result paths. Do not introduce reentrant GC or scheduling at arbitrary allocation points to satisfy quotas; dead guest objects stay charged until safe sweep. Layout headers, metadata, payload capacities, native ownership, auxiliary buffers and temporary storage must have explicit nonduplicated domains. Limits are not RSS or upfront reservations.
|
||||
|
||||
LoadLimits uses the same defaults on hosts; cartridges cannot raise them. Test configurations may lower limits. MiB=1,048,576 bytes.
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
# String provenance qualification
|
||||
|
||||
Measured on 2026-10-14, macOS arm64, Rust 1.98.1, release profile. The workload
|
||||
uses 1,024, 16,384 and 65,536 independently allocated equal-text owners in each
|
||||
image/session domain. Setup is outside query timing. Each query row executes
|
||||
1,000 operations. The native import and mixed snapshot cases call the actual VM
|
||||
boundary methods; a separate diagnostics feature exposes only the fixture.
|
||||
|
||||
Reproduce with:
|
||||
|
||||
```sh
|
||||
cargo run --release -p prometeu-vm --features resource-diagnostics --example string_provenance_benchmark
|
||||
cargo test -p prometeu-vm --test execution_allocations --all-features
|
||||
```
|
||||
|
||||
## Structure and ownership
|
||||
|
||||
Image Weak records are sorted once by allocation data address and UTF-8 length.
|
||||
An in-place heap sort precharges LoadBudget work before each record comparison
|
||||
(four field reads plus comparison) and swap (two reads plus two writes). The
|
||||
existing scratch/retained payload accounting includes the record capacity;
|
||||
sorting adds no auxiliary allocation. Constant-pool and export order, including
|
||||
lease indices, are unchanged. Binary search performs at most floor(log2(N))+1
|
||||
record comparisons for a nonempty table. In-place dead-record retention preserves
|
||||
sorted order.
|
||||
|
||||
Session records use an open-addressed BudgetVec table with no strong content
|
||||
owner, at most 50% live occupancy, geometric growth and tombstones. Full identity
|
||||
is checked after hashing; equal text in another allocation is a miss. Growth and
|
||||
same-capacity rebuild reserve the retained capacity delta in AuxiliaryBytes and
|
||||
the old allocation in TemporaryBytes before allocating or moving records.
|
||||
Publication reserves content and table space before constructing an Arc. Lookup
|
||||
neither reserves nor resizes. Reconciliation removes a key before releasing its
|
||||
Weak and content charges, preventing recycled addresses from matching stale keys.
|
||||
Dead content is still reclaimed at the existing safepoints/pressure pass.
|
||||
|
||||
## Query work and allocator calls
|
||||
|
||||
| Owners per domain | Image hit comparisons before → after | Image miss comparisons before → after | Session hit probes before → after | Session miss probes before → after |
|
||||
| ---: | ---: | ---: | ---: | ---: |
|
||||
| 1,024 | 1024 → 10 | 1024 → 10 | 1024 → 1 | 1024 → 1 |
|
||||
| 16,384 | 16384 → 14 | 16384 → 15 | 16384 → 1 | 16384 → 1 |
|
||||
| 65,536 | 65536 → 16 | 65536 → 17 | 65536 → 2 | 65536 → 1 |
|
||||
|
||||
The hit is the last-created owner, which was last in the original linear ledger.
|
||||
The miss has equal text in a distinct allocation. Hash probe observations depend
|
||||
on allocator-selected addresses and are not worst-case constant-time guarantees.
|
||||
A separate fixed synthetic-key collision fixture verifies chains, full keys and
|
||||
tombstones. Integration tests bound image comparisons and assert zero allocations,
|
||||
reallocations and deallocations for image/session hits/misses and tracked imports
|
||||
at all three sizes. Ordinary string reads still access Arc directly.
|
||||
|
||||
All direct queries and tracked imports reported `[0, 0, 0]` allocator calls
|
||||
before and after. Mixed two-value snapshots reported `[1000, 0, 1000]`, for their
|
||||
Value-vector storage. Untracked imports reported `[1001, 0, 1]`: 1,000 new Arcs
|
||||
plus one table growth; dead content remains Weak-tracked until reconciliation.
|
||||
The benchmark asserts zero calls in the lookup regions; setup, reporting and
|
||||
fixture teardown are excluded. The CI allocator oracle is thread-local.
|
||||
|
||||
## Supporting timings
|
||||
|
||||
Elapsed milliseconds for 1,000 operations; a single local run per implementation,
|
||||
not a percentile estimate or a CI threshold. Warmup, allocator layout, scheduling
|
||||
and CPU frequency can affect these values.
|
||||
|
||||
| Owners | Workload | Linear (ms) | Indexed (ms) |
|
||||
| ---: | --- | ---: | ---: |
|
||||
| 1,024 | `image_hit` | 1.602 | 0.058 |
|
||||
| 1,024 | `image_miss` | 1.511 | 0.046 |
|
||||
| 1,024 | `session_hit` | 1.160 | 0.030 |
|
||||
| 1,024 | `session_miss` | 0.684 | 0.025 |
|
||||
| 1,024 | `import_hit` | 1.513 | 0.101 |
|
||||
| 1,024 | `snapshot_mixed` | 2.031 | 0.216 |
|
||||
| 1,024 | `import_miss` | 2.233 | 0.376 |
|
||||
| 16,384 | `image_hit` | 10.658 | 0.026 |
|
||||
| 16,384 | `image_miss` | 11.847 | 0.023 |
|
||||
| 16,384 | `session_hit` | 10.890 | 0.009 |
|
||||
| 16,384 | `session_miss` | 11.412 | 0.009 |
|
||||
| 16,384 | `import_hit` | 21.726 | 0.035 |
|
||||
| 16,384 | `snapshot_mixed` | 33.012 | 0.083 |
|
||||
| 16,384 | `import_miss` | 22.832 | 0.887 |
|
||||
| 65,536 | `image_hit` | 44.191 | 0.029 |
|
||||
| 65,536 | `image_miss` | 43.959 | 0.025 |
|
||||
| 65,536 | `session_hit` | 47.441 | 0.010 |
|
||||
| 65,536 | `session_miss` | 45.249 | 0.009 |
|
||||
| 65,536 | `import_hit` | 88.518 | 0.038 |
|
||||
| 65,536 | `snapshot_mixed` | 132.199 | 0.094 |
|
||||
| 65,536 | `import_miss` | 90.935 | 3.137 |
|
||||
|
||||
## Creation and memory cost
|
||||
|
||||
The `image_load_ns` diagnostic includes fixture assembly/serialization and sealed
|
||||
loading, not just the sort. Session setup includes the VM, ledger and retained
|
||||
owners. Auxiliary measurements include that fixture's small VM/domain state;
|
||||
image payload measurements include the complete immutable payload, not only its
|
||||
index. These are charged native capacities, not process RSS.
|
||||
|
||||
| Owners | Image fixture before → after (ms) | Session setup before → after (ms) | Session AuxiliaryBytes before → after | Image payload bytes (unchanged) | Session setup allocations before → after |
|
||||
| ---: | ---: | ---: | ---: | ---: | ---: |
|
||||
| 1,024 | 0.600 → 1.128 | 0.236 → 0.348 | 65,696 → 164,016 | 74,072 | 1046 → 1044 |
|
||||
| 16,384 | 1.702 → 4.067 | 1.298 → 2.889 | 1,048,736 → 2,621,616 | 1,179,992 | 16410 → 16408 |
|
||||
| 65,536 | 6.248 → 14.130 | 5.230 → 9.885 | 4,194,464 → 10,485,936 | 4,718,936 | 65564 → 65562 |
|
||||
|
||||
At 65,536 session owners the charged auxiliary footprint rises from roughly 4 MiB
|
||||
to 10 MiB. The 50% occupancy policy costs capacity and increases setup work, while
|
||||
removing whole-ledger traversals at native boundaries. Existing quotas are
|
||||
unchanged; this metadata can reduce available headroom for other session owners.
|
||||
No extra strong Arc owner, guest handle, content interning or new GC schedule was
|
||||
introduced.
|
||||
|
||||
## Refusal and scope of evidence
|
||||
|
||||
Tests force initial allocation, growth and tombstone rebuild failure, auxiliary
|
||||
and coexistence limits, and image sort work exhaustion. They verify no partial
|
||||
entry/content publication, retained live identities and refunded provisional
|
||||
charges. Allocator failures are injected at the fallible allocation seam; stable
|
||||
Arc allocation can still abort on physical allocator exhaustion, as before.
|
||||
Cross-session copies, native lease/snapshot survival and typed storage/root tests
|
||||
remain part of the regression suite. Address ordering can change between loads;
|
||||
the sort refusal fixture is bounded for either order, not tied to a prior address
|
||||
layout.
|
||||
|
||||
These synthetic boundary measurements establish lookup work and ownership
|
||||
behavior. They do not establish gameplay/frame speedups, long-run memory stability,
|
||||
other-platform timings or hardware-independent latency limits. The normative
|
||||
ownership contract is in [Registry and PBX](../specs/runtime/02c-program-registry-and-pbx-v1.md#memory-ownership-and-quotas).
|
||||
Reference in New Issue
Block a user