Make the emit and event names once instead of on every event - #141
Open
nigrosimone wants to merge 1 commit into
Open
nigrosimone wants to merge 1 commit into
nigrosimone wants to merge 1 commit into
Conversation
nigrosimone
marked this pull request as ready for review
October 4, 2026 15:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Connection::Emit()creates a new string for the event name and callsrunInAsyncScope(handle(), "emit", ...)on every readable or writable event. That overload creates the"emit"string again and looks it up by a name that is not internalized, which costs more than the rest of the call. This makes the three names once per connection, internalized.emitis still looked up on every event, so replacing it keeps working.A microbenchmark of the same call (a native object with
EventEmitter.prototypetwo levels up, one listener, Node 26): 662 to 366 ns per event. With pg-native, sequentialSELECT 1on a local Postgres, 20 rounds: client CPU per query 56.96 to 55.99 us (-1.8%; the same build against itself 0.997).The tests pass (84).