mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
The per-stream state records were built as object literals with __proto__: null, which V8 creates as dictionary-mode objects: roughly 50x slower to allocate, and every subsequent property load on them is a dictionary lookup. These records back every hot path, so both stream construction and per-chunk field accesses were paying for it. Replace the literals with classes whose prototype has a null prototype, so instances stay in fast mode while Object.prototype remains excluded from the lookup chain. Every field ever assigned is declared up front so the shape never transitions. Also add benchmark/webstreams/lifecycle.js covering the short-lived stream pattern (create, few chunks, close) that first exposed this. Assisted-by: ChatGPT Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/65625 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>