Skip to content

Commit

Permalink
test(avm): minor benchmarking (#9869)
Browse files Browse the repository at this point in the history
Just a very small micro-benchmark for the a future PR to reference.

This sets up the smallest "worst-case" scenario for the current ephmeral
tree implementation.

1) An initial public data tree is seeded with 128 dummy leaves,
occupying slots 0 to 127
2) We update slot 0 with a new value - this causes the ephemeral tree to
track slot 0 as the `indexedTreeMin`.
3) Inserting 64 new slots (as per a tx), results in 126 DB accesses and
a linear (in the leaf count) search complexity
a) The DB reads occur because the ephemeral tree doesnt track slots 1 to
127
b) All reads are O(n) as we traverse from min leaf to the low leaf info
  • Loading branch information
IlyasRidhuan authored Nov 18, 2024
1 parent 6ed12d9 commit 603b9c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 21 additions & 0 deletions yarn-project/simulator/src/avm/avm_tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,24 @@ describe('AVM Ephemeral Tree Sanity Test', () => {
expect(localRoot.toBuffer()).toEqual(treeInfo.root);
});
});

/* eslint no-console: ["error", { allow: ["time", "timeEnd"] }] */
describe('A basic benchmark', () => {
it('Should benchmark writes', async () => {
// This random is fine for now, since the entry leaves are between 0-127
// We just want to make sure there are minimal "updates" from this set
const leaves = Array.from({ length: 64 }, _ => Fr.random());
const slots = leaves.map((_, i) => new Fr(i + 128));

const container = await AvmEphemeralForest.create(copyState);

// Updating the first slot, triggers the index 0 to be added to the minimum stored key in the container
await container.writePublicStorage(new Fr(0), new Fr(128));
console.time('benchmark');
// These writes are all new leaves and should be impacted by the key sorted algorithm of the tree.
for (let i = 0; i < leaves.length; i++) {
await container.writePublicStorage(slots[i], leaves[i]);
}
console.timeEnd('benchmark');
});
});
4 changes: 0 additions & 4 deletions yarn.lock

This file was deleted.

0 comments on commit 603b9c2

Please sign in to comment.