Skip to content

Commit d4f2391

Browse files
committed
refactor: CogRecord to fixed [Container; 2] = 2KB layout
The "holy grail" change: CogRecord is now exactly 2KB (meta + content), stack-allocated, #[repr(C, align(64))]. Multi-container geometries use linked records in the DN tree instead of Vec<Container>. - Contract: CogRecord { meta: Container, content: Container } - Added as_bytes()/from_bytes() for zero-copy I/O - Updated all callers: geometry, dn_redis, graph, traversal, migrate - Converted orphan impls to extension traits (CogRecordSerde) - All 729 tests pass https://claude.ai/code/session_01NocTBszN8LoR9Vrc7Tn4oF
1 parent 1e0cd11 commit d4f2391

10 files changed

Lines changed: 391 additions & 630 deletions

File tree

crates/ladybug-contract/src/delegation.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,15 @@ mod cogrecord_serde {
4040
pub fn serialize<S: Serializer>(record: &CogRecord, serializer: S) -> Result<S::Ok, S::Error> {
4141
let mut s = serializer.serialize_struct("CogRecord", 2)?;
4242
s.serialize_field("meta", &record.meta.words.as_slice())?;
43-
let content_words: Vec<&[u64]> =
44-
record.content.iter().map(|c| c.words.as_slice()).collect();
45-
s.serialize_field("content", &content_words)?;
43+
s.serialize_field("content", &record.content.words.as_slice())?;
4644
s.end()
4745
}
4846

4947
pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<CogRecord, D::Error> {
5048
#[derive(Deserialize)]
5149
struct Raw {
5250
meta: Vec<u64>,
53-
content: Vec<Vec<u64>>,
51+
content: Vec<u64>,
5452
}
5553

5654
let raw = Raw::deserialize(deserializer)?;
@@ -60,17 +58,10 @@ mod cogrecord_serde {
6058
meta.words[i] = w;
6159
}
6260

63-
let content = raw
64-
.content
65-
.iter()
66-
.map(|words| {
67-
let mut c = Container::zero();
68-
for (i, &w) in words.iter().take(CONTAINER_WORDS).enumerate() {
69-
c.words[i] = w;
70-
}
71-
c
72-
})
73-
.collect();
61+
let mut content = Container::zero();
62+
for (i, &w) in raw.content.iter().take(CONTAINER_WORDS).enumerate() {
63+
content.words[i] = w;
64+
}
7465

7566
Ok(CogRecord { meta, content })
7667
}

crates/ladybug-contract/src/legacy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl From<&V1UnifiedStep> for CogRecord {
237237
"reasoning": step.reasoning,
238238
});
239239
let bytes = serde_json::to_vec(&json).unwrap_or_default();
240-
record.content[0] = content_from_bytes(&bytes);
240+
record.content = content_from_bytes(&bytes);
241241

242242
record
243243
}
@@ -281,7 +281,7 @@ impl From<&V1DataEnvelope> for CogRecord {
281281
// serde envelope until container format is upgraded).
282282
}
283283
let bytes = serde_json::to_vec(&envelope.data).unwrap_or_default();
284-
record.content[0] = content_from_bytes(&bytes);
284+
record.content = content_from_bytes(&bytes);
285285
record
286286
}
287287
}
@@ -337,7 +337,7 @@ impl From<&V1LadybugEnvelope> for CogRecord {
337337
}
338338
}
339339
let bytes = serde_json::to_vec(&envelope.content).unwrap_or_default();
340-
record.content[0] = content_from_bytes(&bytes);
340+
record.content = content_from_bytes(&bytes);
341341
record
342342
}
343343
}

0 commit comments

Comments
 (0)