Skip to content

perf(request): move static getters to prototype for ~2× throughput #6619

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Yanvi09
Copy link

@Yanvi09 Yanvi09 commented Jul 3, 2025

Summary

Express currently uses Object.defineProperty to attach request properties like protocol, secure, ip, ips, hostname, and subdomains on each request instance. While functional, this approach redefines these properties per request, which adds unnecessary overhead in high-load scenarios.

This PR moves those properties to http.IncomingMessage.prototype so they’re defined once and reused across all requests.


Why This Change

  • These properties return consistent values and don’t require redefinition per instance.
  • Moving them to the prototype avoids repeated descriptor setup and reduces per-request allocation.
  • This change preserves behavior while improving performance and memory efficiency.

Impact

  • No changes to request API or behavior — all tests remain green.
  • Adds a regression test to ensure prototype-based getters function as expected.
  • Supports performance improvements outlined in expressjs/perf-wg#15.

Benchmark (Node 20, 1024c)

Before: 6,572 req/s
After: 12,931 req/s
→ That’s about +96% performance boost in real benchmarks.

Reference

Closes: expressjs/perf-wg#15

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.

How to make Express 2x faster
1 participant