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

Reduce buffer allocations #2000

Merged
merged 2 commits into from Jan 13, 2022
Merged

Reduce buffer allocations #2000

merged 2 commits into from Jan 13, 2022

Conversation

lpinca
Copy link
Member

@lpinca lpinca commented Jan 6, 2022

Do not convert strings to Buffers if data does not need to be masked.

Refs: #1998

@lpinca
Copy link
Member Author

lpinca commented Jan 6, 2022

@ronag, this is what I had in mind. Anyway

  1. The API is convoluted.
  2. It is harder to read and maintain.
  3. Buffer.concat(Sender.frame(data, { opcode: 1 })); no longer works if data is a string.

so I'm not ok with merging if the gain is marginal.

@lpinca lpinca force-pushed the reduce/buffer-allocations branch 2 times, most recently from dbb0cf4 to 4461ac6 Compare January 7, 2022 07:48
lib/sender.js Outdated
if (typeof data === 'string') {
if (!options.mask || skipMasking) {
dataLength =
options.byteLength !== undefined
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it is better to hide this behind a symbol property (options[kByteLength]) so that the API cannot be misused. I'm don't know if symbol properties are still slower.

Do not convert strings to `Buffer`s if data does not need to be masked.

Refs: #1998
@lpinca
Copy link
Member Author

lpinca commented Jan 7, 2022

Current implementation addresses my two main concerns:

  1. The API is now simpler.
  2. The data argument of the Sender.frame() function can now be a string but the function always returns a list of Buffers when used externally. Behavior changes when an internal only option(options[kByteLength]) is used.

@ronag what do you think?

@lpinca lpinca merged commit 5b7fbb0 into master Jan 13, 2022
@lpinca lpinca deleted the reduce/buffer-allocations branch January 13, 2022 19:26
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.

None yet

2 participants