-
-
Notifications
You must be signed in to change notification settings - Fork 244
Improve perf of fromCharCode(), fixes #71 #72
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
@nolanlawson any reason you can't apply this optimization to |
OK, done |
function decodeCodePointsArray (buf) { | ||
var len = buf.length | ||
|
||
if (len <= 0x10000) { |
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.
I might pull this constant out and put the explanation comment on it, that way its not magically here.
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.
thanks, that's a good idea!
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.
The issue isn't manual string concatenation; it's doing an unnecessary Array.slice()
when the buffer.length is < 0x10000. I think it's pretty clear that doing slice()
is slower than not doing slice()
, although a JSPerf would tell us exactly how slow.
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.
I can indeed verify that slice is slower than no-slice: http://jsperf.com/string-fromcharcode-apply-vs-string-fromcharcode-using-/4
Improve perf of fromCharCode(), fixes #71
Thanks @nolanlawson |
No prob! Any chance of a 3.4.3 release soon? Would unbreak some of our tests in PouchDB. |
@@ -723,13 +723,17 @@ function asciiSlice (buf, start, end) { | |||
} | |||
|
|||
function binarySlice (buf, start, end) { | |||
var ret = '' | |||
end = Math.min(buf.length, end) |
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.
Will re-add this, shouldn't have been removed.
Probably need to add a test for it.
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.
ah, my bad. sorry!
Cool, that test of ours I mentioned in #70 (the "big png" test) went from 2.7s to 1.4s. Thanks @jessetane for pointing this out!