Improve perf of TextDecoder::decode by re-using TextCodec
In the spec[1], a new decoder is created unconditionally on each call to decode() unless the previous call passed {stream:true}, but in the real world that requires an allocation of a TextCodec object. Since the previous TextCodec would be flushed by the previous decode() call *unless* {stream:true} was passed, then we don't need a new TextCodec to match the spec behavior. On a simple test (64k strings, length 16-32, 50 iterations), the change showed an 11% performance improvement (with a standard deviation of 1.3% over 10 runs). [1] https://encoding.spec.whatwg.org/#dom-textdecoder-decode Bug: 1092582 Change-Id: I815a3e4c2885397aaf24ef790b7470c7ed761ada Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2271061 Commit-Queue: Joshua Bell <jsbell@chromium.org> Reviewed-by:Adam Rice <ricea@chromium.org> Cr-Commit-Position: refs/heads/master@{#784233}
Showing
Please register or sign in to comment