GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: speed up response getHeaders by rozzilla · Pull Request #66592 · nodejs/node

http2: speed up response getHeaders #66592

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.

Sign up for GitHub

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

Merged
nodejs-github-bot merged 1 commit into nodejs:main from rozzilla:perf/http2/speed-up-response-get-headers
Oct 10, 2026
+133 −1
Merged

http2: speed up response getHeaders #66592

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
3362b41
http2: speed up response getHeaders
rozzilla Oct 8, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
http2: speed up response getHeaders
Copy validated header names directly into the shallow result instead
of using ObjectAssign on the internal null-prototype map.

Signed-off-by: Roberto Bianchi <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@rozzilla
rozzilla committed Oct 8, 2026
commit 3362b4158aa4acdd93907f801aa87aa46d30f89d

There are no files selected for viewing

46 changes: 46 additions & 0 deletions 46 benchmark/http2/get-headers.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

const common = require('../common.js');
const assert = require('node:assert');
const http2 = require('node:http2');

const bench = common.createBenchmark(main, {
n: [1e6],
headers: [0, 1, 4, 16, 64],
});

function main({ n, headers }) {
const server = http2.createServer();
server.on('request', (request, response) => {
const expected = { __proto__: null };
for (let index = 0; index < headers; index++) {
const name = `x-header-${index}`;
response.setHeader(name, 'value');
expected[name] = 'value';
}

for (let index = 0; index < 1e4; index++) {
response.getHeaders();
}

let result;
bench.start();
for (let index = 0; index < n; index++) {
result = response.getHeaders();
}
bench.end(n);
assert.deepStrictEqual(result, expected);
response.end();
});

server.listen(0, '127.0.0.1', () => {
const client = http2.connect(`http://127.0.0.1:${server.address().port}`);
const request = client.request();
request.resume();
request.on('end', () => {
client.close();
server.close();
});
request.end();
});
}
8 changes: 7 additions & 1 deletion 8 lib/internal/http2/compat.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,13 @@ class Http2ServerResponse extends Stream {

getHeaders() {
const headers = { __proto__: null };
return ObjectAssign(headers, this[kHeaders]);
const source = this[kHeaders];
const keys = ObjectKeys(source);
for (let index = 0; index < keys.length; index++) {
const key = keys[index];
headers[key] = source[key];
}
return headers;
}

hasHeader(name) {
Expand Down
80 changes: 80 additions & 0 deletions 80 test/parallel/test-http2-compat-get-headers.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

const assert = require('node:assert');
const http2 = require('node:http2');

const server = http2.createServer(common.mustCall((request, response) => {
const empty = response.getHeaders();
assert.strictEqual(Object.getPrototypeOf(empty), null);
assert.deepStrictEqual(Object.keys(empty), []);
assert.notStrictEqual(response.getHeaders(), empty);

const cookies = ['first=value', 'second=value'];
response.setHeader('X-First', 'first');
response.setHeader('10', 'ten');
response.setHeader('2', 'two');
response.setHeader('__proto__', 'proto');
response.setHeader('Constructor', 'constructor');
response.setHeader('Set-Cookie', cookies);

const expected = {
'__proto__': null,
'2': 'two',
'10': 'ten',
'x-first': 'first',
['__proto__']: 'proto',
'constructor': 'constructor',
'set-cookie': cookies,
};
const headers = response.getHeaders();
assert.deepStrictEqual(headers, expected);
assert.deepStrictEqual(Object.keys(headers), Object.keys(expected));
assert.strictEqual(headers['set-cookie'], cookies);
assert.notStrictEqual(response.getHeaders(), headers);

headers['x-first'] = 'changed';
headers['x-new'] = 'new';
delete headers['2'];
assert.deepStrictEqual(response.getHeaders(), expected);

headers['set-cookie'].push('third=value');
assert.strictEqual(response.getHeader('set-cookie'), cookies);
assert.strictEqual(response.getHeader('set-cookie').length, 3);

response.removeHeader('X-First');
response.setHeader('X-First', 'replacement');
delete expected['x-first'];
expected['x-first'] = 'replacement';
assert.deepStrictEqual(response.getHeaders(), expected);
assert.deepStrictEqual(Object.keys(response.getHeaders()), Object.keys(expected));

for (const name of response.getHeaderNames()) {
response.removeHeader(name);
}
assert.deepStrictEqual(response.getHeaders(), empty);
assert.notStrictEqual(response.getHeaders(), empty);

response.setHeader('X-Sent', 'value');
response.flushHeaders();
assert.deepStrictEqual(response.getHeaders(), {
'__proto__': null,
'x-sent': 'value',
':status': 200,
});
response.end();
}));

server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const request = client.request();
request.resume();
request.on('end', common.mustCall(() => {
client.close();
server.close();
}));
request.end();
}));
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.