Skip to content
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

reduce buffer creation for ctr mode #48

Merged
merged 1 commit into from
Aug 18, 2017

Conversation

dignifiedquire
Copy link
Member

When using ctr mode, I saw a large amount of buffer creation + gc when running perf analysis. This avoids generating most of the temporary buffers when running update in ctr mode improving perf in the browser nicely.

self._cache.writeUInt32BE(out[0], offset + 0)
self._cache.writeUInt32BE(out[1], offset + 4)
self._cache.writeUInt32BE(out[2], offset + 8)
self._cache.writeUInt32BE(out[3], offset + 12)
Copy link
Member

Choose a reason for hiding this comment

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

Is this really better than a copy?

Copy link
Member Author

Choose a reason for hiding this comment

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

The writeUint is not better, but the reason I am doing this is that it avoids creating intermediary buffers. Before encryptBlock creates a new buffer, fills it with those four values, just so that the buffer can be copied in here. By using the array directly there is now one less buffer allocation in the loop and together with the preallocation, no buffer allocations are in the loop.

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, my mistake, I thought out was a Buffer.
ACK :)

Copy link

@daviddias daviddias left a comment

Choose a reason for hiding this comment

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

👌🏽

@calvinmetcalf
Copy link
Contributor

calvinmetcalf commented Aug 17, 2017 via email

@dignifiedquire
Copy link
Member Author

@calvinmetcalf that's just githubs diff I pulled part of the function into it's own function, as I needed that functionality

@calvinmetcalf
Copy link
Contributor

oh my bad

@dcousens dcousens merged commit 040d953 into browserify:master Aug 18, 2017
@dcousens
Copy link
Member

@calvinmetcalf could you release?

@ya7ya
Copy link

ya7ya commented Sep 3, 2017

hey @calvinmetcalf @dcousens , When do you think this can be released ?

@daviddias
Copy link

@calvinmetcalf @dcousens yes please! :)

@dcousens
Copy link
Member

dcousens commented Sep 4, 2017

Can't release yet, my local tests throw:

TypeError: invalid key length 128

Investingating within 24 hours

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

Successfully merging this pull request may close these issues.

5 participants