Investigate inconsistent performance of hashTreeRoot()
- Dominant language
- TypeScript
- Stars
- 61
- Forks
- 26
- Avg merge
- 3h 20m
- Merged PRs (30d)
- 6
Description
part of https://github.com/ChainSafe/lodestar/issues/2046
this is a simple test to calculate `hashTreeRoot`
```ts
it.only("set validator valances", function () {
this.timeout(0);
const originalState = state.getOriginalState();
// cache hashTreeRoot
config.types.BeaconState.hashTreeRoot(originalState);
const balances = Array.from({length: originalState.validators.length}, () => BigInt(31217089836));
let minTime = Number.MAX_SAFE_INTEGER;
let maxTime = 0;
let average = {duration: 0, count: 0};
const MAX_TRY = 10000;
for (let i = 0; i < MAX_TRY; i++) {
const state = config.types.BeaconState.clone(originalState);
state.balances = balances as List;
const start = Date.now();
config.types.BeaconState.hashTreeRoot(state);
const duration = Date.now() - start;
const totalDuration = average.duration * average.count + duration;
const totalCount = average.count + 1;
average.count = totalCount;
average.duration = totalDuration / totalCount;
if (duration < minTime) minTime = duration;
if (duration > maxTime) maxTime = duration;
}
console.log("hashTreeRoot minTime:", minTime, "maxTime:", maxTime, "average:", average.duration, "MAX_TRY:", MAX_TRY);
});
```
this prints out `hashTreeRoot minTime: 65 maxTime: 507 average: 80.46129999999977 MAX_TRY: 10000`. I notice the max time is very similar to the one we have during a long epoch transition.
we need to investigate why the performance is inconsistent and if we can improve it.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.