Skip to content

Commit 93f5ffd

Browse files
committed
Merge release/0.1.21 into main
Brings the PVA tracker-state memory ceiling and the 0.1.22 version bump onto the mainline. The released line was cut from origin/main and never merged back, so main carried neither the feature nor the published version. Workspace version resolved to 0.1.22 (the published one) over main's stale 0.1.20. # Conflicts: # Cargo.toml # spvirit-py/pyproject.toml
2 parents 39acbf3 + efcf609 commit 93f5ffd

5 files changed

Lines changed: 642 additions & 17 deletions

File tree

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ resolver = "2"
77
# in step: `spvirit-py/pyproject.toml` pins `spvirit-tools` by exact version,
88
# and `spvirit-tools/tests/version_pin.rs` fails the build if it drifts.
99
[workspace.package]
10-
version = "0.1.20"
10+
version = "0.1.22"
1111

1212
# Internal crates are declared once so their version is not repeated across
1313
# five manifests. Members refer to them with `workspace = true`.
1414
[workspace.dependencies]
15-
spvirit-types = { version = "0.1.20", path = "spvirit-types" }
16-
spvirit-codec = { version = "0.1.20", path = "spvirit-codec" }
17-
spvirit-client = { version = "0.1.20", path = "spvirit-client" }
18-
spvirit-server = { version = "0.1.20", path = "spvirit-server" }
19-
spvirit-ioc = { version = "0.1.20", path = "spvirit-ioc" }
15+
spvirit-types = { version = "0.1.22", path = "spvirit-types" }
16+
spvirit-codec = { version = "0.1.22", path = "spvirit-codec" }
17+
spvirit-client = { version = "0.1.22", path = "spvirit-client" }
18+
spvirit-server = { version = "0.1.22", path = "spvirit-server" }
19+
spvirit-ioc = { version = "0.1.22", path = "spvirit-ioc" }

spvirit-codec/src/spvd_decode.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ impl FieldType {
143143
FieldType::BoundedString(_) => "string",
144144
}
145145
}
146+
147+
/// Bytes this type owns on the heap, walked recursively.
148+
///
149+
/// Only the nesting variants own anything; scalars are pure discriminant.
150+
pub fn heap_size(&self) -> usize {
151+
match self {
152+
FieldType::Structure(s) | FieldType::StructureArray(s) => s.heap_size(),
153+
FieldType::Union(f) | FieldType::UnionArray(f) => {
154+
f.capacity() * std::mem::size_of::<FieldDesc>()
155+
+ f.iter().map(FieldDesc::heap_size).sum::<usize>()
156+
}
157+
_ => 0,
158+
}
159+
}
146160
}
147161

148162
/// Field description (name + type)
@@ -152,6 +166,13 @@ pub struct FieldDesc {
152166
pub field_type: FieldType,
153167
}
154168

169+
impl FieldDesc {
170+
/// Bytes this field owns on the heap, including any nested structure.
171+
pub fn heap_size(&self) -> usize {
172+
self.name.capacity() + self.field_type.heap_size()
173+
}
174+
}
175+
155176
/// Structure description with optional ID
156177
#[derive(Debug, Clone, PartialEq)]
157178
pub struct StructureDesc {
@@ -171,6 +192,20 @@ impl StructureDesc {
171192
pub fn field(&self, name: &str) -> Option<&FieldDesc> {
172193
self.fields.iter().find(|f| f.name == name)
173194
}
195+
196+
/// Bytes this description owns on the heap, walked recursively.
197+
///
198+
/// Introspection is the one term in the state tracker's memory estimate
199+
/// that is both large and expensive to measure: an NTScalar carries
200+
/// thirty-odd nested `FieldDesc` nodes, each with its own name. Callers
201+
/// are expected to cache this at assignment rather than re-walk the tree
202+
/// on every accounting pass.
203+
pub fn heap_size(&self) -> usize {
204+
let id = self.struct_id.as_ref().map_or(0, |s| s.capacity());
205+
let fields = self.fields.capacity() * std::mem::size_of::<FieldDesc>()
206+
+ self.fields.iter().map(FieldDesc::heap_size).sum::<usize>();
207+
id + fields
208+
}
174209
}
175210

176211
impl Default for StructureDesc {

0 commit comments

Comments
 (0)