perf(storage): prototype compact PieceV2 storage - #292
Conversation
Record storage reads, writes, KAMT object locality, and persistent slot growth for additions to an existing data set. This establishes the baseline for the compact piece representation work. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Document the compact PieceV2 design and split the prototype into sequential, agent-ready implementation digests with explicit invariants, acceptance criteria, verification, and handoff requirements. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Reject ambiguous and malformed CID encodings before they can be stored or used for proof verification. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Append the two-slot compact piece mapping and centralize bounded metadata packing before production paths adopt the new storage. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Store newly added pieces in compact slots with their final Fenwick sums, while batching the dataset leaf-count update.\n\nThis removes legacy addition writes ahead of migrating readers and removers. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Serve piece getters, pagination, CID search, and deletion scheduling from compact metadata while preserving canonical CID output and mapping-style getter defaults. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Adapt behavioral and raw-storage tests to compact piece records, including Fenwick sums and cleanup reclamation. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Run generation after layout cleanup so make cannot evaluate generated targets before their files are removed. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Measure isolated 1, 4, 16, and 32-piece additions and lock the observed storage activity. Document the compact baseline, slot reductions, and KAMT alignment behavior. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Keep the consolidated measurement comparison and align the four-piece KAMT baseline with the revised measurement method. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
063dea8 to
1145d1f
Compare
Add deterministic storage population for reproducing the deployed verifier's large state tree during Filecoin gas benchmarks. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
…-add-pieces-2 Signed-off-by: Jakub Sztandera <oss@kubuxu.com> # Conflicts: # src/PDPVerifier.sol # src/PDPVerifierLayout.json # src/PDPVerifierLayout.sol
Keep compact-storage coverage while preserving the established sum-tree names in tests. Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
|
Benchmark results: Optimised gas reduction versus baseline:
Flat gas used
The optimisation largely removes ballast sensitivity: at 5M slots, batch 32 falls from 2.260B to 200.3M gas (91.1%, or 11.3× lower). Batch 64 is excluded because both versions revert at the Lotus event-size limit. Benchmarks were performed in foc-devnet, ballasting down the PDPVerifier tree with the added dev-only |
| @@ -0,0 +1,359 @@ | |||
| ## Recommendation | |||
There was a problem hiding this comment.
I plan to remove this doc. It was generated as part of LLM task guidance.
|
@rvagg @wjmelements I would appreciate an early review. I don't expect the logic to change much, but it will get way messier when I make this backwards compatible. |
But I think we can fix that here can't we because (a) we're emitting those events with uncapped arrays of piece CIDs and (b) the piece CID we're emitting are the larger legacy format, not the compact 64-byte format; so we could go quite high, at least for the PDPVerifier component (FWSS will impose its own limits), right? |
Summary
Draft implementation of the compact two-slot
PieceV2storage prototype, related to #286.New compact-state datasets store pieces in a contiguous per-dataset array:
metadatapacks padding, tree height, leaf count, and the Fenwick partial sum into one storage slot.Changes
PieceCIDv2validation and decoded(padding, height, root)in one pass.PieceV2storage while retaining the existing declarations for physical layout safety.addPiecesstorage activity for 1, 4, 16, and 32-piece batches.Storage measurements
Each scenario creates a fresh dataset, adds one seed piece before recording, then records the measured
addPiecescall.Values are
legacy → compact.Findings
5N → 2Nnewly occupied slots.7Nto3N + 1; reduction grows from 42.9% at one piece to 56.7% at 32 pieces.At 32 pieces, the compact layout occupies 64 slots instead of 160, touches 9 KAMT objects instead of 137, and modifies 5 instead of 132.
Compatibility note
This is a forward-only prototype. Backwards compatibility for datasets created before the compact representation was not considered.
Keep this PR as draft; it is not ready to merge or deploy as an upgrade.
Verification