Skip to content

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

Merged
merged 1 commit into from
Aug 15, 2015
Merged

Conversation

nolanlawson
Copy link
Collaborator

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!

@dcousens
Copy link
Collaborator

@nolanlawson any reason you can't apply this optimization to binarySlice?

@nolanlawson
Copy link
Collaborator Author

OK, done

function decodeCodePointsArray (buf) {
var len = buf.length

if (len <= 0x10000) {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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!

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

dcousens added a commit that referenced this pull request Aug 15, 2015
Improve perf of fromCharCode(), fixes #71
@dcousens dcousens merged commit fd60fb3 into feross:master Aug 15, 2015
@dcousens
Copy link
Collaborator

Thanks @nolanlawson

@nolanlawson
Copy link
Collaborator Author

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)
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah, my bad. sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants