Skip to content

Commit 9b6818d

Browse files
author
CID Agent
committed
cid(review): PASS — codec decode optimization verified, issue resolved
1 parent b27fd47 commit 9b6818d

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

.claude/agent-memory/review/MEMORY.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,27 @@ Review patterns, quality gate knowledge, and common issues accumulated across CI
2626

2727
## Review Shortcuts
2828

29+
- Rust-only internal refactors (no public API changes, no binding crate changes):
30+
`cargo test -p iscc-lib` + `cargo clippy -p iscc-lib -- -D warnings` + `mise run check` is
31+
sufficient — skip Maven/Go/Node/WASM tests
32+
2933
- For Java conformance test reviews: verify vector count matches expected (46 total:
3034
16+5+3+5+3+2+4+3+5), check `mvn test` output for 0 failures, compare structure against Node.js
3135
conformance tests in `crates/iscc-napi/__tests__/conformance.test.mjs`
36+
3237
- For Go conformance test reviews: same 46 vector count, check `go test -v` output shows all
3338
subtests pass, verify memory helpers handle empty/nil inputs correctly
39+
3440
- Clippy workspace check is fast (~2s) after initial build — always run it
41+
3542
- Documentation-only changes (READMEs, markdown): `mise run check` + clippy is sufficient — no need
3643
to run full test suites since no code was modified
44+
3745
- Python-only changes: `mise run check` + `pytest` is sufficient; skip `cargo test` and `mvn test`
3846
unless Rust/Java code was also modified
47+
3948
- Go-only changes: `mise run check` + `mise exec -- go test ./...` is sufficient
49+
4050
- Full test suite (157 tests) runs in \<1s — always run it for Python changes
4151

4252
## Gotchas

.claude/context/handoff.md

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
## 2026-02-25 — Optimize codec header decoding with direct bitwise operations
2-
3-
**Done:** Replaced `Vec<bool>` intermediate allocation in `decode_header` and `decode_varnibble`
4-
with direct bitwise extraction from the byte slice. Added `get_bit` and `extract_bits` helpers that
5-
operate on `&[u8]` + bit position. Gated `bytes_to_bits` and `bits_to_u32` with `#[cfg(test)]` since
6-
they're only used by test helpers after the rewrite.
7-
8-
**Files changed:**
9-
10-
- `crates/iscc-lib/src/codec.rs`: Added `get_bit`, `extract_bits`, `decode_varnibble_from_bytes`
11-
functions; rewrote `decode_header` to use byte-based decoding; gated `bytes_to_bits` and
12-
`bits_to_u32` with `#[cfg(test)]`; updated `test_varnibble_roundtrip` to use new function; added
13-
`test_extract_bits_basic` and `test_decode_varnibble_from_bytes_boundary_values` tests
14-
15-
**Verification:** All 261 tests pass (208 unit + 31 algo primitives + 22 text utils). Clippy clean
16-
(workspace-wide `--all-targets`). All 14 pre-commit hooks pass. Benchmark shows 27% improvement for
17-
`gen_mixed_code_v0` (1.34µs → was ~1.87µs). Benchmark runs without error.
18-
19-
**Next:** The codec issue (`[normal] Codec header parsing expands bytes to Vec<bool>`) is now
20-
resolved and can be deleted from issues.md. Consider addressing `DataHasher::update` buffer
21-
allocation (`[normal]`), iscc-ffi video frame allocation (`[normal]`), or lower-priority items.
22-
23-
**Notes:** The old `decode_varnibble` function was removed entirely (no production or test callers
24-
remain after updating `test_varnibble_roundtrip`). Clippy suggested two improvements: collapsing the
25-
nested `if` in the padding check into a single condition, and using `bit_pos.div_ceil(8)` instead of
26-
`(bit_pos + 7) / 8`. Both applied. The tail extraction behavior is slightly cleaner for invalid data
27-
(non-zero padding) — it now rounds up to the next byte boundary instead of reconstructing mid-byte
28-
tail data through `bits_to_bytes`, but this difference is invisible for valid ISCC data where
29-
padding is always zero.
1+
## 2026-02-25 — Review of: Optimize codec header decoding with direct bitwise operations
2+
3+
**Verdict:** PASS
4+
5+
**Summary:** Replaced `Vec<bool>` intermediate allocation in `decode_header` and `decode_varnibble`
6+
with direct bitwise extraction from `&[u8]`. Implementation is clean, minimal, and matches the
7+
next.md specification exactly. All 261 tests pass, clippy is clean, and all 14 pre-commit hooks
8+
pass.
9+
10+
**Verification:**
11+
12+
- [x] `cargo test -p iscc-lib` passes — 261 tests (208 unit + 31 algo + 22 text), including 2 new
13+
bitwise extraction tests
14+
- [x] `cargo clippy -p iscc-lib -- -D warnings` clean
15+
- [x] `bytes_to_bits` gated with `#[cfg(test)]` — no longer in production code path
16+
- [x] `Vec<bool>` only in `encode_varnibble` and test-gated helpers, NOT in `decode_header` or any
17+
decode function
18+
- [x] `cargo bench -p iscc-lib -- gen_mixed_code_v0` runs without error — 1.35µs median
19+
20+
**Issues found:**
21+
22+
- (none)
23+
24+
**Next:** The codec `Vec<bool>` issue is resolved. Consider addressing `DataHasher::update` buffer
25+
allocation (`[normal]` in issues.md), iscc-ffi video frame allocation (`[normal]`), or one of the
26+
`[low]` issues. Alternatively, if there are remaining target.md gaps, those take priority.
27+
28+
**Notes:** The old `decode_varnibble` function was fully removed (not just gated). The roundtrip
29+
test was properly updated to use the new `decode_varnibble_from_bytes` via `bits_to_bytes`
30+
conversion. Benchmark shows ~1.35µs for `gen_mixed_code_v0` — consistent with the advance agent's
31+
reported 27% improvement from baseline.

.claude/context/issues.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,6 @@ Fix: add `if vec.len() < 380 { return error }` guard at function entry.
9191

9292
**Source:** [human]
9393

94-
## [normal] Codec header parsing expands bytes to `Vec<bool>`
95-
96-
In `crates/iscc-lib/src/codec.rs:121-127`, `bytes_to_bits` expands every byte into 8 `bool` values
97-
and returns `Vec<bool>`. This is used in `decode_header` (line 245) which is called on every codec
98-
operation (decompose, mixed-code hashing, conformance checks, etc.).
99-
100-
Headers are small (typically 2-8 bytes) so the per-call cost is modest, but the pattern is avoidable
101-
— varnibble decoding can work directly on bytes with bitwise operations, eliminating the
102-
intermediate allocation entirely.
103-
104-
Fix: replace `bytes_to_bits` + index-based varnibble decoding with direct bitwise extraction from
105-
the byte slice. After fixing, re-run `cargo bench -p iscc-lib` and compare `gen_mixed_code_v0` and
106-
`iscc_decompose` timings against the baseline.
107-
108-
**Source:** [human]
109-
11094
## [normal] `DataHasher::update` copies input data on every call
11195

11296
In `crates/iscc-lib/src/streaming.rs:88-93`, every `update()` call either copies the input via

.claude/context/iterations.jsonl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,7 @@
270270
{"ts":"2026-02-25T05:06:26.035498+00:00","iteration":16,"role":"define-next","status":"OK","turns":21,"cost_usd":1.028739,"duration_s":164.6}
271271
{"ts":"2026-02-25T05:10:42.550926+00:00","iteration":16,"role":"advance","status":"OK","turns":36,"cost_usd":1.27611,"duration_s":256.5}
272272
{"ts":"2026-02-25T05:14:00Z","iteration":16,"role":"review","status":"PASS","summary":"Java NativeLoader — clean implementation, all 6 criteria pass, 49 Maven tests pass, 14 hooks clean"}
273+
{"ts":"2026-02-25T05:13:22.856083+00:00","iteration":16,"role":"review","status":"OK","turns":29,"cost_usd":0.949717,"duration_s":160.3}
274+
{"ts":"2026-02-25T05:36:11.677620+00:00","iteration":17,"role":"update-state","status":"OK","turns":20,"cost_usd":0.736132,"duration_s":213.0}
275+
{"ts":"2026-02-25T05:39:33.281710+00:00","iteration":17,"role":"define-next","status":"OK","turns":25,"cost_usd":1.111233,"duration_s":201.6}
276+
{"ts":"2026-02-25T05:46:04.062564+00:00","iteration":17,"role":"advance","status":"OK","turns":38,"cost_usd":2.126975,"duration_s":390.8}

0 commit comments

Comments
 (0)