Skip to content

buffer: reduce overhead of StringBytes::Encode for UCS2#19798

Closed
joyeecheung wants to merge 1 commit intonodejs:masterfrom
joyeecheung:ucs2-copy
Closed

buffer: reduce overhead of StringBytes::Encode for UCS2#19798
joyeecheung wants to merge 1 commit intonodejs:masterfrom
joyeecheung:ucs2-copy

Conversation

@joyeecheung
Copy link
Copy Markdown
Member

@joyeecheung joyeecheung commented Apr 4, 2018

Currently calling StringBytes::Encode on a UCS2 buffer
results in two copies of the buffer and the usage of
std::vector::assign makes the memory usage unpredictable,
and therefore hard to test against.

This patch makes the memory usage more predictable by
allocating the memory using node::UncheckedMalloc and
handles the memory allocation failure properly. Only
one copy of the buffer will be created and it will
be freed upon GC of the string.

This was discovered in #19739 when
ensuring twice of the memory taken up by the buffer still does not prevent malloc failures.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Refs: #19739

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants