-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Improve how DecodeStream handles empty buffers. #5025
Improve how DecodeStream handles empty buffers. #5025
Conversation
DecodeStream currently initializes its |buffer| field to |null|, which is reasonable, because lots of DecodeStreams never need to instantiate a buffer. But this requires various special cases in the code. This patch change it so DecodeStreamClosure has a single empty Uint8Array which gets shared between all buffers upon initialization. This avoids the special cases. DecodeStream.prototype.ensureBuffer() is really hot, and this removes a test from the fast path. For one 226 page scanned document this sped up rendering by about 2%.
what is the risk of accidentally writing to the empty buffer? |
In a typed array, if you read from out-of-bounds elements, you get Firefox's nsTArray has a similar optimization -- there's a single shared header used for empty arrays. That's where I got the idea. |
ok, got it, you are saying because you inited it with zero length it will never contain data. thats good. |
That's right; if a bigger buffer is needed it will be allocated on demand. Any document that uses CCITTFaxStreams heavily would be a good test, because |
I like that change.
|
/botio test |
From: Bot.io (Linux)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.21.233.14:8877/984acca3150d725/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.22.172.223:8877/6c5380298dfb162/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/984acca3150d725/output.txt Total script time: 36.79 mins
|
Improve how DecodeStream handles empty buffers.
Thanks for the patch! |
DecodeStream currently initializes its |buffer| field to |null|, which
is reasonable, because lots of DecodeStreams never need to instantiate a
buffer. But this requires various special cases in the code.
This patch change it so DecodeStreamClosure has a single empty
Uint8Array which gets shared between all buffers upon initialization.
This avoids the special cases.
DecodeStream.prototype.ensureBuffer() is really hot, and this removes a
test from the fast path. For one 226 page scanned document this sped up
rendering by about 2%.