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

http/server : Header parsing perf enhancement #337

wants to merge 1 commit into from


2 participants
Copy link

zekth commented Apr 13, 2019

Just changed the header parsing way to use an array instead of string concat. This speeds up 0.02ms earch request in average.

Here is the test code to use with --allow-high-precision

let s, e;
let headers: Headers = new Headers();
for (let i = 0; i < 10; i++) {
    "head-" + i,
const average = arr => arr.reduce( ( p, c ) => p + c, 0 ) / arr.length;
const str = [];
const arr = [];
for (let i = 0; i < 500; i++) {
  s =;
  let out = "";
  if (headers) {
    for (const [key, value] of headers) {
      out += `${key}: ${value}\r\n`;
  out += "\r\n";
  e =;
  str.push(e - s);

  s =;
  let outArr = [];
  if (headers) {
    headers.forEach((v,k) => outArr.push(`${k}: ${v}\r\n`))
  e =;
  arr.push(e - s);

console.log(`String implementation: ${average(str)}ms`);
console.log(`Array implementation: ${average(arr)}ms`);

// String implementation: 0.07737456799999913ms
// Array implementation: 0.05701406000000017ms

This comment has been minimized.

Copy link

ry commented Apr 14, 2019

See my comment here: #338 (comment)
If you can move the numbers in the benchmark, I'm interested. But this will not make a difference.
I appreciate the patch but closing without merge.

@ry ry closed this Apr 14, 2019

@zekth zekth deleted the zekth:perf-improvement branch Apr 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.