Skip to content

Commit

Permalink
chore: update the benchmark dependencies (#429)
Browse files Browse the repository at this point in the history
* Update the benchmark dependencies

* Fix lint error

* Fix the benchmark files

* Update the benchmark version

* Remove dead code

* Update package version

* Update package version

* Test the hasher for performance regression

* Revert "Test the hasher for performance regression"

This reverts commit d98e64f.

* Update the package version

* Update the rc version of benchmark

* Update the benchmark version

* Sort the benchmarks

* Update the benchmark rc file

* Celanup GC

* Disable hasher to test

* Disable hasher to test

* Revert hasher change

* Update the setup file to include a hook

* Update the sethasher loging

* Update the benchmark lib version

* Cleanup the hasher

* Bump package version

* Remove gc flag

* fix(persistent-ts): empty commit to trigger release from package.json fix

* fix(ssz): empty commit to trigger release from package.json fix

---------

Co-authored-by: matthewkeil <me@matthewkeil.com>
nazarhussain and matthewkeil authored Jan 17, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 2fd9c04 commit 3d931df
Showing 46 changed files with 708 additions and 809 deletions.
12 changes: 5 additions & 7 deletions .benchrc.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Mocha opts
colors: true
require:
- ts-node/register
- setHasher.mjs

# benchmark opts
threshold: 3
maxMs: 60_000
maxMs: 60000
minRuns: 10
triggerGC: false
sort: true
setupFiles:
- ./setHasher.mjs
4 changes: 0 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ module.exports = {
browser: true,
es6: true,
node: true,
mocha: true,
},
globals: {
BigInt: true,
@@ -79,9 +78,6 @@ module.exports = {
quotes: ["error", "double"],
semi: "off",

// Prevents accidentally pushing a commit with .only in Mocha tests
"no-only-tests/no-only-tests": "error",

// TEMP Disabled while eslint-plugin-import support ESM (Typescript does support it) https://github.com/import-js/eslint-plugin-import/issues/2170
"import/no-unresolved": "off",
},
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -26,9 +26,7 @@
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
"@babel/register": "^7.15.3",
"@dapplion/benchmark": "^0.2.2",
"@types/chai": "^4.2.15",
"@types/mocha": "^8.2.2",
"@chainsafe/benchmark": "^1.1.0",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^6",
"@typescript-eslint/parser": "^6",
@@ -41,7 +39,6 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"lerna": "^8.1.3",
"mocha": "^9.0.1",
"prettier": "^2.2.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
@@ -54,7 +51,6 @@
"webpack-dev-server": "^3.11.2"
},
"resolutions": {
"@types/react": "^17.0",
"chai": "4.5.0"
"@types/react": "^17.0"
}
}
}
3 changes: 1 addition & 2 deletions packages/as-sha256/package.json
Original file line number Diff line number Diff line change
@@ -47,7 +47,6 @@
},
"devDependencies": {
"@chainsafe/babel-plugin-inline-binary-import": "^1.0.3",
"assemblyscript": "^0.27.24",
"benchmark": "^2.1.4"
"assemblyscript": "^0.27.24"
}
}
16 changes: 8 additions & 8 deletions packages/as-sha256/test/perf/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {itBench, setBenchOpts} from "@dapplion/benchmark";
import {bench, describe, setBenchOpts} from "@chainsafe/benchmark";
import {
digest,
digest2Bytes32,
@@ -26,15 +26,15 @@ describe("digestTwoHashObjects vs digest64 vs digest", () => {
const obj2 = byteArrayToHashObject(buffer2, 0);
// total number of time running hash for 200000 balances
const iterations = 50023;
itBench(`digestTwoHashObjects ${iterations} times`, () => {
bench(`digestTwoHashObjects ${iterations} times`, () => {
for (let j = 0; j < iterations; j++) digest64HashObjects(obj1, obj2);
});

itBench(`digest2Bytes32 ${iterations} times`, () => {
bench(`digest2Bytes32 ${iterations} times`, () => {
for (let j = 0; j < iterations; j++) digest2Bytes32(buffer1, buffer2);
});

itBench(`digest ${iterations} times`, () => {
bench(`digest ${iterations} times`, () => {
for (let j = 0; j < iterations; j++) digest(input);
});
});
@@ -45,7 +45,7 @@ describe("digest different Buffers", () => {

for (const length of [32, 64, 128, 256, 512, 1024]) {
const buffer = randomBuffer(length);
itBench(`input length ${length}`, () => {
bench(`input length ${length}`, () => {
digest(buffer);
});
}
@@ -64,7 +64,7 @@ describe("hash - compare to java", () => {
const iterations = 1000000;
const input = Buffer.from("lwkjt23uy45pojsdf;lnwo45y23po5i;lknwe;lknasdflnqw3uo5", "utf8");

itBench(`digest ${iterations} times`, () => {
bench(`digest ${iterations} times`, () => {
for (let i = 0; i < iterations; i++) digest(input);
});
});
@@ -81,12 +81,12 @@ describe("utils", () => {
// total number of time running hash for 200000 balances
const iterations = 50023;

itBench(`hashObjectToByteArray ${iterations} times`, () => {
bench(`hashObjectToByteArray ${iterations} times`, () => {
const byteArr = new Uint8Array(32);
for (let j = 0; j < iterations; j++) hashObjectToByteArray(obj1, byteArr, 0);
});

itBench(`byteArrayToHashObject ${iterations} times`, () => {
bench(`byteArrayToHashObject ${iterations} times`, () => {
for (let j = 0; j < iterations; j++) byteArrayToHashObject(buffer1, 0);
});
});
12 changes: 5 additions & 7 deletions packages/as-sha256/test/perf/simd.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {itBench, setBenchOpts} from "@dapplion/benchmark";
import {bench, describe, setBenchOpts} from "@chainsafe/benchmark";
import {batchHash4HashObjectInputs, batchHash4UintArray64s, digest64, digest64HashObjects} from "../../src/index.js";
import {byteArrayToHashObject} from "../../src/hashObject.js";

@@ -12,34 +12,32 @@ import {byteArrayToHashObject} from "../../src/hashObject.js";
✓ hash 200092 times using batchHash4HashObjectInputs 9.211751 ops/s 108.5570 ms/op - 88 runs 10.1 s
*/
describe("digest64 vs batchHash4UintArray64s vs digest64HashObjects vs batchHash4HashObjectInputs", function () {
this.timeout(0);

setBenchOpts({
minMs: 10_000,
});

const input = Buffer.from("gajindergajindergajindergajindergajindergajindergajindergajinder", "utf8");
// total number of time running hash for 200000 balances
const iterations = 50023;
itBench(`digest64 ${iterations * 4} times`, () => {
bench(`digest64 ${iterations * 4} times`, () => {
for (let j = 0; j < iterations * 4; j++) digest64(input);
});

// batchHash4UintArray64s do 4 sha256 in parallel
itBench(`hash ${iterations * 4} times using batchHash4UintArray64s`, () => {
bench(`hash ${iterations * 4} times using batchHash4UintArray64s`, () => {
for (let j = 0; j < iterations; j++) {
batchHash4UintArray64s([input, input, input, input]);
}
});

const hashObject = byteArrayToHashObject(Buffer.from("gajindergajindergajindergajinder", "utf8"), 0);
itBench(`digest64HashObjects ${iterations * 4} times`, () => {
bench(`digest64HashObjects ${iterations * 4} times`, () => {
for (let j = 0; j < iterations * 4; j++) digest64HashObjects(hashObject, hashObject);
});

const hashInputs = Array.from({length: 8}, () => hashObject);
// batchHash4HashObjectInputs do 4 sha256 in parallel
itBench(`hash ${iterations * 4} times using batchHash4HashObjectInputs`, () => {
bench(`hash ${iterations * 4} times using batchHash4HashObjectInputs`, () => {
for (let j = 0; j < iterations; j++) {
batchHash4HashObjectInputs(hashInputs);
}
10 changes: 5 additions & 5 deletions packages/persistent-merkle-tree/test/perf/gindex.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {itBench} from "@dapplion/benchmark";
import {describe, bench} from "@chainsafe/benchmark";
import {getGindexBits, getGindicesAtDepth, gindexIterator, iterateAtDepth} from "../../src/index.js";

describe("gindices at depth", () => {
@@ -9,14 +9,14 @@ describe("gindices at depth", () => {
// ✓ getGindicesAtDepth 188146.8 ops/s 5.315000 us/op x0.587 1788863 runs 10.1 s
// ✓ iterateAtDepth 89047.20 ops/s 11.23000 us/op x0.977 867266 runs 10.0 s

itBench("getGindicesAtDepth", () => {
bench("getGindicesAtDepth", () => {
const gindices = getGindicesAtDepth(depth, startIx, count);
for (let i = 0; i < gindices.length; i++) {
//
}
});

itBench("iterateAtDepth", () => {
bench("iterateAtDepth", () => {
for (let gindex of iterateAtDepth(depth, BigInt(startIx), BigInt(count))) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
gindex++;
@@ -30,14 +30,14 @@ describe("gindex bits", () => {
// ✓ getGindexBits 1381215 ops/s 724.0000 ns/op - 9967639 runs 10.6 s
// ✓ gindexIterator 801282.1 ops/s 1.248000 us/op - 6466357 runs 10.2 s

itBench("getGindexBits", () => {
bench("getGindexBits", () => {
const bits = getGindexBits(gindex);
for (let i = 0; i < bits.length; i++) {
!!bits[i];
}
});

itBench("gindexIterator", () => {
bench("gindexIterator", () => {
for (const bit of gindexIterator(gindex)) {
!!bit;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {itBench} from "@dapplion/benchmark";
import { HashComputation, HashComputationLevel, LeafNode, zeroHash } from "../../src/index.js";
import {describe, bench} from "@chainsafe/benchmark";
import {HashComputation, HashComputationLevel, LeafNode, zeroHash} from "../../src/index.js";

/**
* HashComputationLevel push then loop is faster than HashComputation[] push then loop
@@ -15,7 +15,7 @@ describe("HashComputationLevel", function () {

const length = 2_000_000;

itBench({
bench({
id: "HashComputationLevel.push then loop",
before: () => new HashComputationLevel(),
beforeEach: (level) => {
@@ -30,10 +30,10 @@ describe("HashComputationLevel", function () {
for (const hc of level) {
const {src0, src1, dest} = hc;
}
}
},
});

itBench({
bench({
id: "HashComputation[] push then loop",
fn: () => {
const level: HashComputation[] = [];
@@ -43,6 +43,6 @@ describe("HashComputationLevel", function () {
for (const hc of level) {
const {src0, src1, dest} = hc;
}
}
})
},
});
});
16 changes: 7 additions & 9 deletions packages/persistent-merkle-tree/test/perf/hasher.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {itBench} from "@dapplion/benchmark";
import {describe, bench} from "@chainsafe/benchmark";
import {Hasher, HashObject, setHasher, uint8ArrayToHashObject} from "../../src/hasher/index.js";
import {hasher as asSha256Hasher} from "../../src/hasher/as-sha256.js";
import {hasher as nobleHasher} from "../../src/hasher/noble.js";
@@ -7,8 +7,6 @@ import {buildComparisonTrees} from "../utils/tree.js";
import {HashComputationLevel, getHashComputations} from "../../src/index.js";

describe("hasher", function () {
this.timeout(0);

const iterations = 500_000;

const root1 = new Uint8Array(32);
@@ -25,7 +23,7 @@ describe("hasher", function () {
const runsFactor = 10;
for (const hasher of hashers) {
describe(hasher.name, () => {
itBench({
bench({
id: `hash 2 Uint8Array ${iterations} times - ${hasher.name}`,
fn: () => {
for (let i = 0; i < runsFactor; i++) {
@@ -35,7 +33,7 @@ describe("hasher", function () {
runsFactor,
});

itBench({
bench({
id: `hashTwoObjects ${iterations} times - ${hasher.name}`,
before: () => ({
obj1: uint8ArrayToHashObject(root1),
@@ -51,7 +49,7 @@ describe("hasher", function () {
runsFactor,
});

itBench({
bench({
id: `executeHashComputations - ${hasher.name}`,
beforeEach: () => {
const [tree] = buildComparisonTrees(16);
@@ -68,7 +66,7 @@ describe("hasher", function () {
});

describe("hashtree", function () {
itBench({
bench({
id: "getHashComputations",
beforeEach: () => {
const [tree] = buildComparisonTrees(16);
@@ -80,7 +78,7 @@ describe("hashtree", function () {
},
});

itBench({
bench({
id: "executeHashComputations",
beforeEach: () => {
const [tree] = buildComparisonTrees(16);
@@ -93,7 +91,7 @@ describe("hashtree", function () {
},
});

itBench({
bench({
id: "get root",
beforeEach: async () => {
const [tree] = buildComparisonTrees(16);
18 changes: 9 additions & 9 deletions packages/persistent-merkle-tree/test/perf/node.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {itBench} from "@dapplion/benchmark";
import {describe, bench} from "@chainsafe/benchmark";
import {BranchNode, getNodeH, LeafNode} from "../../src/node.js";
import {countToDepth, getHashComputations, subtreeFillToContents} from "../../src/index.js";
import {batchHash} from "../utils/batchHash.js";
@@ -9,19 +9,19 @@ describe("HashObject LeafNode", () => {

const zeroLeafNode = LeafNode.fromZero();

itBench(`getNodeH() x${nodesPerSlot} avg hindex`, () => {
bench(`getNodeH() x${nodesPerSlot} avg hindex`, () => {
for (let i = 0; i < nodesPerSlot; i++) {
getNodeH(zeroLeafNode, i % 8);
}
});

itBench(`getNodeH() x${nodesPerSlot} index 0`, () => {
bench(`getNodeH() x${nodesPerSlot} index 0`, () => {
for (let i = 0; i < nodesPerSlot; i++) {
getNodeH(zeroLeafNode, 0);
}
});

itBench(`getNodeH() x${nodesPerSlot} index 7`, () => {
bench(`getNodeH() x${nodesPerSlot} index 7`, () => {
for (let i = 0; i < nodesPerSlot; i++) {
getNodeH(zeroLeafNode, 7);
}
@@ -30,13 +30,13 @@ describe("HashObject LeafNode", () => {
// As fast as previous methods
const keys: (keyof LeafNode)[] = ["h0", "h1", "h2", "h3", "h4", "h5", "h6", "h7"];

itBench(`getNodeH() x${nodesPerSlot} index 7 with key array`, () => {
bench(`getNodeH() x${nodesPerSlot} index 7 with key array`, () => {
for (let i = 0; i < nodesPerSlot; i++) {
zeroLeafNode[keys[7]];
}
});

itBench(`new LeafNode() x${nodesPerSlot}`, () => {
bench(`new LeafNode() x${nodesPerSlot}`, () => {
for (let i = 0; i < nodesPerSlot; i++) {
LeafNode.fromHashObject(zeroLeafNode);
}
@@ -47,23 +47,23 @@ describe("Node batchHash", () => {
const numNodes = [250_000, 500_000, 1_000_000];

for (const numNode of numNodes) {
itBench({
bench({
id: `getHashComputations ${numNode} nodes`,
beforeEach: () => createList(numNode),
fn: (rootNode: BranchNode) => {
getHashComputations(rootNode, 0, []);
},
});

itBench({
bench({
id: `batchHash ${numNode} nodes`,
beforeEach: () => createList(numNode),
fn: (rootNode: BranchNode) => {
batchHash(rootNode);
},
});

itBench({
bench({
id: `get root ${numNode} nodes`,
beforeEach: () => createList(numNode),
fn: (rootNode: BranchNode) => {
Loading

0 comments on commit 3d931df

Please sign in to comment.