Replace DataView.getUint8 by typed array access #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Using DataView is currently still slower than directly accessing a typed array. For the case of the expression
dataView.getUint8(offset)
it is possible to circumvent the use of DataView and directly use a typed array. This is possible since the DataView is initialized with a 1 byte element length, which makes it equivalent to a direct Uint8Array view of the data.With this change, there are speed increases of 15% on Chrome 47 and 36% on Firefox 42 on my machine while decoding around 200MiB of data. Testing was done with a very large array of numbers where one third of elements were nulls.
I am working with such big data, so I would be happy if this is merged. Typically the data I have compresses extremely well (60MiB get down to 2MiB after gzipping in my case) so the bottleneck is the CBOR decoding after the data is unzipped. And this change is one step in making cbor-js a bit faster.
Test code: