-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
Add noAssert to Buffer::write #4126
Comments
I read the v8 source again and found the trick is that |
No doubt there's more we can do here. For example we could short circuit the Thanks for posting the issue. I'll look further into what can be done here. |
Nevermind about partially what I said. |
Just tested the |
So the problem is we call // src/lib/buffer.js
function fromString(string, encoding) {
...
var length = byteLength(string, encoding);
if(length === string.length && encoding === 'utf8') {
encoding = 'binary'
} And it should make a difference because this call is avoided. The next two problems are:
|
What's the status on this one? |
Pull request demonstrating an improved implementation would be appreciated, of course, Otherwise, this issue has been inactive for sufficiently long that it seems like perhaps it should be closed. Feel free to re-open (or leave a comment requesting that it be re-opened) if you disagree. I'm just tidying up and not acting on a super-strong opinion or anything like that. |
Currently the
new Buffer(string)
constructor callsutf8Length
andwrite
, which can be very slow, becauseBuffer::write
calls StringBytes::Write and which callsv8::String::WriteUtf8
with abuffer
address and itscapacity
same as theutf8Length
of the string. Butv8::String::WriteUtf8
will be very fast if passed with acapacity
equals to or larger than three times of the string length (see here).So I think, why don't we manually make sure the capacity of the buffer is large enough, and pass a larger
capacity
(for example, three times of the string length) to theWriteUtf8
method, to make it faster?The text was updated successfully, but these errors were encountered: