-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
buffer: improve Buffer.byteLength(string, encoding) #1441
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
Conversation
|
It is an edge case too. Benchmark test case is: Result is here: for empty string, about 100x times improved. |
lib/buffer.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just do if (string.length === 0) return 0; here? That would trim down the diff a bunch. :)
|
The diff would be a lot cleaner if you did this before the if (string.length === 0)
return 0; |
16ea356 to
4a28077
Compare
|
thanks @Fishrock123 and @cjihrig , updated. |
|
In your benchmark results, where is the performance improvement coming from on non-empty strings? |
|
@cjihrig the difference of two non-empty strings result maybe in 1% deviation. maybe can be ignored. |
|
Yea, likely just noise. LGTM, but the |
4a28077 to
c5c33c5
Compare
|
updated. |
When string is empty, it will running into binding also. It make the performance is wasted.
c5c33c5 to
7c00ec2
Compare
|
LGTM |
|
+1 |
|
LGTM |
When the string is empty, calling the binding is unnecessary and slow. PR-URL: #1441 Reviewed-by: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Christian Tellnes <[email protected]>
|
Thanks, landed in 431673e |
When string is empty, it will running into binding also.
It make the performance is wasted.