Skip to content

Commit b56c06b

Browse files
perf(v3): cache compiled qualified implementation fingerprint (#102)
Cache the immutable compiled qualified-family implementation fingerprint in a process-local OnceLock<[u8; 32]>, preserving the existing Vec return API. Keep all 15 source components, domain separator, length prefixes and digest bytes unchanged; every database catalog, shape, policy, identity and physical-stamp check still runs. Owned nightly formatting, offline source equivalence and candidate/patch checks pass. Native typecheck, Clippy, PostgreSQL tests and performance measurements remain pending.
1 parent 21b7f89 commit b56c06b

1 file changed

Lines changed: 56 additions & 48 deletions

File tree

‎src/jupiter/storage/qualified_metadata_family.rs‎

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Captured physical Q provisioning and the sealed rooted production repository.
22
3+
use std::sync::OnceLock;
4+
35
use mst2_codec::metapage::{HEADER_LEN, PAGE_MAX_BYTES};
46
use sea_orm::{
57
ConnectionTrait, DatabaseConnection, DatabaseTransaction, DbBackend, IsolationLevel, Statement,
@@ -132,54 +134,60 @@ fn literal(value: &str) -> String {
132134
format!("'{}'", value.replace('\'', "''"))
133135
}
134136
pub(crate) fn implementation_fingerprint() -> Vec<u8> {
135-
let mut hash = Sha256::new();
136-
hash.update(b"mega.mst2.rooted-qualified-implementation.v1\0");
137-
// Length-prefix every source component so source selection and proof
138-
// revisions cannot change while retaining an accepted physical stamp.
139-
for (name, bytes) in [
140-
("family", FAMILY.as_bytes()),
141-
("family-ddl", FAMILY_SQL.as_bytes()),
142-
("canonical-proof-revision-1", CANONICAL_SQL.as_bytes()),
143-
("indexed-source-read-revision-1", SOURCE_READ_SQL.as_bytes()),
144-
("captured-source-revision-1", SOURCE_REVISION_SQL.as_bytes()),
145-
("rooted-collector-revision-1", GC_SQL.as_bytes()),
146-
(
147-
"bounded-reader-lifecycle-revision-1",
148-
READER_LIFECYCLE_SQL.as_bytes(),
149-
),
150-
("typed-certificate-revision-1", CERTIFICATES_SQL.as_bytes()),
151-
(
152-
"source-attestation-and-anchor-revision-1",
153-
ANCHORS_SQL.as_bytes(),
154-
),
155-
("rooted-plan-and-bindings-revision-1", ROOTED_SQL.as_bytes()),
156-
(
157-
"rooted-session-and-reader-revision-1",
158-
SERVING_SQL.as_bytes(),
159-
),
160-
(
161-
"rooted-physical-route-revision-1",
162-
include_bytes!("../migration/m20261008_000200_rooted_routes.sql").as_slice(),
163-
),
164-
(
165-
"authority-catalog-selector",
166-
include_bytes!("qualified_family_catalog.sql").as_slice(),
167-
),
168-
(
169-
"normalized-family-shape",
170-
include_bytes!("qualified_family_shape.sql").as_slice(),
171-
),
172-
(
173-
"initial-core-registration",
174-
include_bytes!("../migration/m20261008_000200_rooted_qualified_family.sql").as_slice(),
175-
),
176-
] {
177-
hash.update((name.len() as u64).to_le_bytes());
178-
hash.update(name.as_bytes());
179-
hash.update((bytes.len() as u64).to_le_bytes());
180-
hash.update(bytes);
181-
}
182-
hash.finalize().to_vec()
137+
static FINGERPRINT: OnceLock<[u8; 32]> = OnceLock::new();
138+
FINGERPRINT
139+
.get_or_init(|| {
140+
let mut hash = Sha256::new();
141+
hash.update(b"mega.mst2.rooted-qualified-implementation.v1\0");
142+
// Length-prefix every source component so source selection and proof
143+
// revisions cannot change while retaining an accepted physical stamp.
144+
for (name, bytes) in [
145+
("family", FAMILY.as_bytes()),
146+
("family-ddl", FAMILY_SQL.as_bytes()),
147+
("canonical-proof-revision-1", CANONICAL_SQL.as_bytes()),
148+
("indexed-source-read-revision-1", SOURCE_READ_SQL.as_bytes()),
149+
("captured-source-revision-1", SOURCE_REVISION_SQL.as_bytes()),
150+
("rooted-collector-revision-1", GC_SQL.as_bytes()),
151+
(
152+
"bounded-reader-lifecycle-revision-1",
153+
READER_LIFECYCLE_SQL.as_bytes(),
154+
),
155+
("typed-certificate-revision-1", CERTIFICATES_SQL.as_bytes()),
156+
(
157+
"source-attestation-and-anchor-revision-1",
158+
ANCHORS_SQL.as_bytes(),
159+
),
160+
("rooted-plan-and-bindings-revision-1", ROOTED_SQL.as_bytes()),
161+
(
162+
"rooted-session-and-reader-revision-1",
163+
SERVING_SQL.as_bytes(),
164+
),
165+
(
166+
"rooted-physical-route-revision-1",
167+
include_bytes!("../migration/m20261008_000200_rooted_routes.sql").as_slice(),
168+
),
169+
(
170+
"authority-catalog-selector",
171+
include_bytes!("qualified_family_catalog.sql").as_slice(),
172+
),
173+
(
174+
"normalized-family-shape",
175+
include_bytes!("qualified_family_shape.sql").as_slice(),
176+
),
177+
(
178+
"initial-core-registration",
179+
include_bytes!("../migration/m20261008_000200_rooted_qualified_family.sql")
180+
.as_slice(),
181+
),
182+
] {
183+
hash.update((name.len() as u64).to_le_bytes());
184+
hash.update(name.as_bytes());
185+
hash.update((bytes.len() as u64).to_le_bytes());
186+
hash.update(bytes);
187+
}
188+
hash.finalize().into()
189+
})
190+
.to_vec()
183191
}
184192
pub(crate) fn render_family(
185193
core_schema: &str,

0 commit comments

Comments
 (0)