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(node/buffer): improve utf8 decoding performance #2986

Merged
merged 1 commit into from
Dec 7, 2022

Conversation

anonrig
Copy link
Contributor

@anonrig anonrig commented Dec 6, 2022

Microbenchmarks show 29x improvement of decoding uint8array

cpu: Apple M1 Max
runtime: deno 1.28.3 (aarch64-apple-darwin)

benchmark               time (avg)             (min … max)       p75       p99      p995
---------------------------------------------------------- -----------------------------
• bench
---------------------------------------------------------- -----------------------------
buf.toString         55.06 µs/iter  (52.58 µs … 240.75 µs)  53.46 µs 105.67 µs 109.08 µs
textdecoder length     1.9 µs/iter     (1.88 µs … 2.02 µs)   1.91 µs   2.02 µs   2.02 µs

summary for bench
  textdecoder length
   28.92x faster than buf.toString
Benchmark implementation
const buf = Buffer.from(large)
const decoder = new TextDecoder()

group({ name: 'bench', summary: true }, () => {
  bench('buf.toString', () => {
    return buf.toString()
  })

  bench('textdecoder length', () => {
    return decoder.decode(large);
  })
})

await run({
  avg: true, // enable/disable avg column (default: true)
  json: false, // enable/disable json output (default: false)
  colors: true, // enable/disable colors (default: true)
  min_max: true, // enable/disable min/max column (default: true)
  // collect: false, // enable/disable collecting returned values into an array during the benchmark (default: false)
  // percentiles: false, // enable/disable percentiles column (default: true)
})

@CLAassistant
Copy link

CLAassistant commented Dec 6, 2022

CLA assistant check
All committers have signed the CLA.

@anonrig
Copy link
Contributor Author

anonrig commented Dec 6, 2022

Invalid benchmarks

@anonrig anonrig closed this Dec 6, 2022
@anonrig anonrig reopened this Dec 6, 2022
@anonrig
Copy link
Contributor Author

anonrig commented Dec 6, 2022

I was wrong, this is 29x faster. Re-opening pull request

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @anonrig, very impressive results!

Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

LGTM!

@bartlomieju bartlomieju merged commit 8167508 into denoland:main Dec 7, 2022
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.

4 participants