Skip to content
This repository was archived by the owner on Mar 18, 2022. It is now read-only.

Add setNodes() method #53

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

Add setNodes() method #53

wants to merge 2 commits into from

Conversation

dapplion
Copy link
Contributor

@dapplion dapplion commented Aug 3, 2021

Motivation

TransientVector from persistent-ts uses an optimization for faster setting of many nodes where each new node is only created once.

Description

Apply a similar strategy to the binary tree where with multiple gindexes and nodes each BranchNode is navigated and created at most once. Depending on the distribution of the array on gindexes this approach is either x2 faster or as fast as updating individually

    ✓ setNode loop depth 40 count 8 - contiguous                          118764.8 ops/s    8.420000 us/op        -      92889 runs   1.00 s
    ✓ setNodes depth 40 count 8 - contiguous                              232450.0 ops/s    4.302000 us/op        -     158404 runs   1.01 s
    ✓ setNode loop depth 40 count 8 - spread                              120380.4 ops/s    8.307000 us/op        -      98473 runs   1.01 s
    ✓ setNodes depth 40 count 8 - spread                                  132432.8 ops/s    7.551000 us/op        -     104445 runs   1.01 s
    ✓ setNode loop depth 40 count 32 - contiguous                         32047.17 ops/s    31.20400 us/op        -      26036 runs   1.00 s
    ✓ setNodes depth 40 count 32 - contiguous                             75585.79 ops/s    13.23000 us/op        -      48814 runs   1.00 s
    ✓ setNode loop depth 40 count 32 - spread                             27498.97 ops/s    36.36500 us/op        -      22871 runs   1.00 s
    ✓ setNodes depth 40 count 32 - spread                                 36836.48 ops/s    27.14700 us/op        -      28710 runs   1.00 s
    ✓ setNode loop depth 40 count 256 - contiguous                        3738.248 ops/s    267.5050 us/op        -       3146 runs   1.00 s
    ✓ setNodes depth 40 count 256 - contiguous                            10048.43 ops/s    99.51800 us/op        -       6658 runs   1.00 s
    ✓ setNode loop depth 40 count 256 - spread                            3236.675 ops/s    308.9590 us/op        -       2763 runs   1.00 s
    ✓ setNodes depth 40 count 256 - spread                                4283.077 ops/s    233.4770 us/op        -       3546 runs   1.00 s

Closes #49

@github-actions
Copy link

github-actions bot commented Aug 3, 2021

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: ea2924d Previous: 42b42e6 Ratio
hash 2 Uint8Array 2250026 times 3.1818 s/op 2.6847 s/op 1.19
hashTwoObjects 2250026 times 2.9813 s/op 2.5374 s/op 1.17
setRoot - gindexBitstring 11.182 ms/op 13.190 ms/op 0.85
setRoot - gindex 11.976 ms/op 13.406 ms/op 0.89
getRoot - gindexBitstring 13.381 ms/op 15.436 ms/op 0.87
getRoot - gindex 14.679 ms/op 14.224 ms/op 1.03
getHashObject - gindex 14.047 ms/op 13.944 ms/op 1.01
setHashObject - gindex 11.278 ms/op 13.121 ms/op 0.86
250k validators 3.2538 s/op 2.8874 s/op 1.13

by benchmarkbot/action

@dapplion dapplion force-pushed the dapplion/add-setNodes branch 2 times, most recently from d877e37 to 6886fc1 Compare August 19, 2021 09:36
@dapplion dapplion force-pushed the dapplion/add-setNodes branch from 78adb77 to c6d659e Compare August 28, 2021 14:46
@dapplion
Copy link
Contributor Author

@wemeetagain Would you mind taking over this PR?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add efficient multi setter: setNodes / setMany
3 participants