-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for some reason, this is MUCH faster!
- Loading branch information
1 parent
d47673b
commit 91649a6
Showing
1 changed file
with
32 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91649a6
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 think DataView is just really slow... that's my theory.
91649a6
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.
That is a testable theory!
The problem here is that DataView is the only native way to control endianness,
although of course you can do bitwise ops.
The problem is that hashing expects a particular byte order, but TypedArrays use the hardware default byte order,
so, you have to write JAVASCRIPT that knows whether it's on a x86 (LE) or some weird ARM (BE)
91649a6
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.
Oh, by the way, I noticed that in your Buffer polyfil,
that you create a new
DataView
for eachreadUint32BE
(etc) op,maybe that is the problem?
91649a6
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.
Nope! There's a single DataView that is initialized here (https://github.com/feross/native-buffer-browserify/blob/master/index.js#L1047) and reused for each buffer.
I only create a
DataView
for areadUint32BE
, etc. call in certain edge cases. If the read would go off the edge of the buffer, then that's a special case. In node, the bytes that are off the edge are filled in with zero. But the browser throws an exception in that case! So when I detect that case, I make a new ArrayBuffer and fill in the valid bytes manually, leaving the rest to be zero.91649a6
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'm going to investigate getting rid of the DataView and doing it via bitwise ops to see if it's any faster!
91649a6
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.
Not sure if you saw, but bitwise ops was a lot faster: feross/buffer#8