Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark-test(shared-tree): Implement read/write execution time benchmark #21088

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

chentong7
Copy link
Contributor

@chentong7 chentong7 commented May 15, 2024

Description

We want to have execution time benchmark tests for read and write speed on the simple-tree layer (for now) of SharedTree. Look at packages/dds/tree/src/test/shared-tree/sharedTree.bench.ts for inspiration. That file covers some of the scenarios that we want to benchmark.

Sample

  SimpleTree benchmarks
spec.js:54
    Direct SimpleTree
spec.js:54
      ✔ @Benchmark @Measurement @ExecutionTime Deep Tree as SimpleTree: reads with 1 nodes
spec.js:76
      ✔ @Benchmark @Perspective @ExecutionTime Deep Tree as SimpleTree: reads with 10 nodes
spec.js:76
      ✔ @Benchmark @Measurement @ExecutionTime Deep Tree as SimpleTree: reads with 100 nodes
spec.js:76
      ✔ @Benchmark @Measurement @ExecutionTime Wide Tree as SimpleTree: reads with 1 nodes
spec.js:76
      ✔ @Benchmark @Perspective @ExecutionTime Wide Tree as SimpleTree: reads with 100 nodes
spec.js:76
      ✔ @Benchmark @Measurement @ExecutionTime Wide Tree as SimpleTree: reads with 500 nodes
spec.js:76
      Edit SimpleTree
spec.js:54
        ✔ @Benchmark @Measurement @ExecutionTime Update value at leaf of 1 deep tree
spec.js:76
        ✔ @Benchmark @Perspective @ExecutionTime Update value at leaf of 10 deep tree
spec.js:76
        ✔ @Benchmark @Measurement @ExecutionTime Update value at leaf of 100 deep tree
spec.js:76
        ✔ @Benchmark @Measurement @ExecutionTime Update value at leaf of 1 Wide tree
spec.js:76
        ✔ @Benchmark @Perspective @ExecutionTime Update value at leaf of 100 Wide tree
spec.js:76
        ✔ @Benchmark @Measurement @ExecutionTime Update value at leaf of 500 Wide tree
spec.js:76
  12 passing (150ms)
SimpleTree benchmarks Read SimpleTree
Results file: /home/tong/workspace/FluidFramework/node_modules/.pnpm/@fluid-tools+benchmark@0.48.0/node_modules/@fluid-tools/benchmark/dist/.output/SimpleTree_benchmarks_Read_SimpleTree_perfresult.json
status  name                                           period (ns/op)  relative margin of error  iterations per batch  batch count  total time (s)
------  ---------------------------------------------  --------------  ------------------------  --------------------  -----------  --------------
    ✔   Deep Tree as SimpleTree: reads with 1 nodes          3,842.93                    ±9.83%                16,384           80            5.11
    ✔   Deep Tree as SimpleTree: reads with 10 nodes        92,774.94                   ±18.97%                 1,024           53            5.12
    ✔   Deep Tree as SimpleTree: reads with 100 nodes    2,106,151.86                    ±4.65%                    32           74            5.07
    ✔   Wide Tree as SimpleTree: reads with 1 nodes         29,892.08                   ±16.84%                 4,096           40            5.01
    ✔   Wide Tree as SimpleTree: reads with 100 nodes      885,287.25                   ±16.88%                    64           87            5.01
    ✔   Wide Tree as SimpleTree: reads with 500 nodes    3,800,340.77                    ±7.98%                    16           81            5.00
 
 
SimpleTree benchmarks Edit SimpleTree
Results file: /home/tong/workspace/FluidFramework/node_modules/.pnpm/@fluid-tools+benchmark@0.48.0/node_modules/@fluid-tools/benchmark/dist/.output/SimpleTree_benchmarks_Edit_SimpleTree_perfresult.json
status  name                                   period (ns/op)  relative margin of error  iterations per batch  batch count  total time (s)
------  -------------------------------------  --------------  ------------------------  --------------------  -----------  --------------
    ✔   Update value at leaf of 1 deep tree         48,345.98                    ±5.36%                   512          199            5.01
    ✔   Update value at leaf of 10 deep tree       167,054.64                    ±5.29%                   256          115            5.02
    ✔   Update value at leaf of 100 deep tree    2,462,559.79                    ±6.66%                    32           63            5.09
    ✔   Update value at leaf of 1 Wide tree        125,448.51                    ±4.68%                   256          153            5.02
    ✔   Update value at leaf of 100 Wide tree      122,261.31                    ±4.46%                   256          157            5.02
    ✔   Update value at leaf of 500 Wide tree      136,890.41                    ±5.31%                   256          140            5.01

@chentong7 chentong7 requested a review from a team as a code owner May 15, 2024 02:21
@github-actions github-actions bot added area: dds Issues related to distributed data structures area: dds: tree base: main PRs targeted against main branch labels May 15, 2024
@chentong7 chentong7 requested a review from a team May 15, 2024 18:02
@chentong7 chentong7 force-pushed the benchmark branch 3 times, most recently from fc56f85 to 058e13d Compare May 20, 2024 22:53
@github-actions github-actions bot added the public api change Changes to a public API label May 22, 2024
@github-actions github-actions bot removed the public api change Changes to a public API label May 22, 2024
packages/dds/tree/src/test/simple-tree/simpleTree.bench.ts Outdated Show resolved Hide resolved
packages/dds/tree/src/test/simple-tree/simpleTree.bench.ts Outdated Show resolved Hide resolved
packages/dds/tree/src/test/simple-tree/utils.ts Outdated Show resolved Hide resolved
packages/dds/tree/src/test/simple-tree/utils.ts Outdated Show resolved Hide resolved
packages/dds/tree/src/test/simple-tree/utils.ts Outdated Show resolved Hide resolved
packages/dds/tree/src/test/simple-tree/utils.ts Outdated Show resolved Hide resolved
packages/dds/tree/src/test/simple-tree/utils.ts Outdated Show resolved Hide resolved
packages/dds/tree/src/test/simple-tree/utils.ts Outdated Show resolved Hide resolved
packages/dds/tree/src/test/simple-tree/utils.ts Outdated Show resolved Hide resolved
packages/dds/tree/src/test/simple-tree/simpleTree.bench.ts Outdated Show resolved Hide resolved
@chentong7 chentong7 force-pushed the benchmark branch 2 times, most recently from 356fcc8 to 9723123 Compare May 22, 2024 20:12
Comment on lines 148 to 153
/**
* write the wide tree with a new value
*/
export function writeWideSimpleTree(tree: WideTreeNode, newValue: number): void {
const nodesCount = tree.values.length;
for (let i = 0; i < nodesCount; i++) {
tree.values.removeAt(i);
tree.values.insertAt(i, newValue);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea of what this function needed to do to test the scenario we want is different, not replacing every node in the array, just updating the last node in the array. Because that would let us test that the cost (runtime) of doing this is more or less constant regardless of how wide the tree is, since we're just replacing one node in each case. Replacing every node in the tree could still be an interesting scenario, and we would expect it to be more expensive as the width of the tree grows, but my understanding is that we want to test replacing just one (the last) node regardless of tree width. @taylorsw04 any thoughts on this?

Comment on lines 136 to 142
export function readWideSimpleTree(tree: WideTreeNode): {
nodesCount: number;
sum: number;
} {
const nodesCount = tree.values.length;
let sum = 0;
for (const value of tree.values) {
sum += value;
}
return { nodesCount, sum };
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the concern in my previous comment applies to this one too. This function iterates over the whole tree, which we can reasonably expect to be more expensive as the tree grows. If instead of reading the whole tree sequentially, we did "random access" with tree.values[tree.values.length - 1], we maybe would expect constant-ish time regardless of the tree width. Again @taylorsw04 , thoughts on which case we want to test? Or both, so we can check if the increase in execution time with tree size is linear or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: dds: tree area: dds Issues related to distributed data structures base: main PRs targeted against main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants