Skip to content

Commit 91c7f8c

Browse files
committed
perf(stack-encrypt): read a record's context field in place
Each sealed field's closure read the record's context field by copying the frame and parsing the copy, once per field per row. The frame is now read in place through `IntoLabel for &ValueFrame`, so what each field does per row is one parse of a short text and no copy. Parsing once per row would need a slot the field closures share, which the description has no place for: each field's `under_by` sees the row alone. Refs #1488.
1 parent 9675de4 commit 91c7f8c

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎packages/stack-encrypt/src/dynamic/planned.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,12 +975,13 @@ fn check_names(values: &FieldValues, names: &[String]) -> Result<(), crate::Erro
975975
Ok(())
976976
}
977977

978-
/// The context a record's context field holds.
978+
/// The context a record's context field holds, read in place: each sealed
979+
/// field's closure reads it once per row, a parse of a short text, and
980+
/// copies nothing for it.
979981
fn context_of(values: &FieldValues, field: &str) -> Result<Label, crate::Error> {
980982
values
981983
.get::<ValueFrame>(field)
982984
.ok_or_else(|| field_type(field, type_name::<ValueFrame>()))?
983-
.clone()
984985
.into_label()
985986
.map_err(|error| PlanError::ContextLabel(error).into())
986987
}

‎packages/stack-encrypt/src/dynamic/value_frame.rs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,9 @@ impl PartialEq for ValueFrame {
406406
/// A text value read as a plan's context: what a data plan's
407407
/// `"context_field"` holds (`"tenants/acme"`), parsed as a Rust chain's
408408
/// `String` context field is ([`Label::parse`]). Anything else is
409-
/// [`LabelError::NotText`].
410-
impl IntoLabel for ValueFrame {
409+
/// [`LabelError::NotText`]. The frame is read in place: a record's context
410+
/// field is read once per sealed field, and nothing is copied for it.
411+
impl IntoLabel for &ValueFrame {
411412
fn into_label(self) -> Result<Label, LabelError> {
412413
self.visit(super::term::OneScalar::new(
413414
|ty: Option<Logical>, value: Physical<'_>| match (ty, value) {
@@ -419,6 +420,12 @@ impl IntoLabel for ValueFrame {
419420
}
420421
}
421422

423+
impl IntoLabel for ValueFrame {
424+
fn into_label(self) -> Result<Label, LabelError> {
425+
(&self).into_label()
426+
}
427+
}
428+
422429
// =============================================================================
423430
// The value model, as a sink adapter
424431
// =============================================================================

0 commit comments

Comments
 (0)