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

perf(codec): improve bytify and hexify perf #580

Merged
merged 1 commit into from
Dec 6, 2023
Merged

perf(codec): improve bytify and hexify perf #580

merged 1 commit into from
Dec 6, 2023

Conversation

homura
Copy link
Collaborator

@homura homura commented Dec 6, 2023

Description

A performance issue was found in #579

Type of change

  • Refactor (non-breaking change)

How Has This Been Tested?

benchmark.js
import Benchmark from "benchmark";
import { randomBytes } from "node:crypto";
import bytesOld from "./lib/bytes.js";
import bytesNew from "./lib/bytes-new.js";

const bytesData = randomBytes(10000);
const hexData = bytesNew.hexify(bytesData);

const suite = Benchmark.Suite();

suite
  .add("hexify-old", () => {
    bytesOld.hexify(bytesData);
  })
  .add("hexify-new", () => {
    bytesNew.hexify(bytesData);
  })
  .add("bytify-old", () => {
    bytesOld.bytify(hexData);
  })
  .add("bytify-new", () => {
    bytesNew.bytify(hexData);
  })
  .on("cycle", (event) => {
    console.log(String(event.target));
  })
  .run();
➜  codec git:(perf-bytes) ✗ bun run bench.mjs
hexify-old x 1,328 ops/sec ±0.38% (95 runs sampled)
hexify-new x 4,606 ops/sec ±0.33% (95 runs sampled)
bytify-old x 1,192 ops/sec ±0.51% (95 runs sampled)
bytify-new x 4,597 ops/sec ±0.29% (96 runs sampled)
➜  codec git:(perf-bytes) ✗ clear
➜  codec git:(perf-bytes) ✗ bun run bench.mjs
hexify-old x 1,325 ops/sec ±0.36% (95 runs sampled)
hexify-new x 4,524 ops/sec ±0.30% (97 runs sampled)
bytify-old x 1,184 ops/sec ±0.42% (96 runs sampled)
bytify-new x 4,547 ops/sec ±0.31% (95 runs sampled)
➜  codec git:(perf-bytes) ✗ node bench.mjs
hexify-old x 2,079 ops/sec ±0.75% (96 runs sampled)
hexify-new x 21,727 ops/sec ±1.01% (93 runs sampled)
bytify-old x 2,320 ops/sec ±0.29% (97 runs sampled)
bytify-new x 2,440 ops/sec ±0.38% (98 runs sampled)
➜  codec git:(perf-bytes) ✗ node bench.mjs
hexify-old x 2,092 ops/sec ±0.74% (93 runs sampled)
hexify-new x 22,277 ops/sec ±0.49% (99 runs sampled)
bytify-old x 2,319 ops/sec ±0.39% (97 runs sampled)
bytify-new x 2,467 ops/sec ±0.17% (99 runs sampled)
➜  codec git:(perf-bytes) ✗ node --version
v21.3.0
➜  codec git:(perf-bytes) ✗ bun --version    
1.0.15

Copy link

vercel bot commented Dec 6, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
lumos-website ✅ Ready (Inspect) Visit Preview Dec 6, 2023 10:39am

Copy link

codecov bot commented Dec 6, 2023

Codecov Report

Merging #580 (80ef246) into develop (8424b07) will decrease coverage by 2.35%.
The diff coverage is 96.93%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #580      +/-   ##
===========================================
- Coverage    87.07%   84.73%   -2.35%     
===========================================
  Files          116      116              
  Lines        23453    23506      +53     
  Branches      2380     2262     -118     
===========================================
- Hits         20421    19917     -504     
- Misses        2988     3546     +558     
+ Partials        44       43       -1     
Files Coverage Δ
packages/codec/src/bytes.ts 98.43% <97.22%> (-0.60%) ⬇️
packages/codec/src/utils.ts 94.53% <96.77%> (-1.47%) ⬇️

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8424b07...80ef246. Read the comment docs.

@homura homura merged commit b8e9396 into develop Dec 6, 2023
7 of 8 checks passed
@github-actions github-actions bot mentioned this pull request Dec 6, 2023
@homura homura deleted the perf-bytes branch December 6, 2023 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants