[JSC] Do not allocate unnecessary UTF-8 string for encodeXXX functions
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Jun 2016 17:23:11 +0000 (17:23 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Jun 2016 17:23:11 +0000 (17:23 +0000)
commitdd00cd1dcde347e10159b09f19d0b7bfb9c18395
tree66654ad2b83db720c0483940d35eb9d7896ee3e4
parent372e70723f5cc3592c7c6f6d9fbf35bc0386a0a8
[JSC] Do not allocate unnecessary UTF-8 string for encodeXXX functions
https://bugs.webkit.org/show_bug.cgi?id=158416

Reviewed by Darin Adler and Geoffrey Garen.

Source/JavaScriptCore:

Previously, encodeXXX functions first allocate new UTF-8 string, and generate (& allocate) the results from this UTF-8 string.
It is costly since this UTF-8 string is always wasted. In this patch, we generate the results without this UTF-8 string.
We precisely implement ECMA262's Encode abstract operation[1].

This optimized encodeXXX functions provide great improvement in kraken stanford-crypto-sha256-iterative since it frequently calls
these functions. We can see 6 - 7% improvements.

                                              baseline                  patched

stanford-crypto-sha256-iterative           37.952+-0.155      ^      35.484+-0.265         ^ definitely 1.0695x faster

[1]: https://tc39.github.io/ecma262/#sec-encode

* runtime/JSGlobalObjectFunctions.cpp:
(JSC::toSafeView):
Use this helper function to retrieve JSString::SafeView.

(JSC::makeCharacterBitmap):
(JSC::encode):
In encode, we reserve N length buffer at first. This is important when the length of the given string is long enough,
preventing frequent unnecessary buffer reallocations. This reserving contributes to 1% kraken stanford-crypto-sha256-iterative progression.

(JSC::decode):
Previously, Bitmap accidentally includes \0. And instead of removing this \0, we checked character != 0.
This patch fixes it for the Bitmap not to include \0.

(JSC::globalFuncParseInt):
(JSC::globalFuncEscape):
(JSC::globalFuncUnescape):
* tests/stress/encode-decode-ascii.js: Added.
(shouldBe):
* tests/stress/encode-decode-unicode.js: Added.
(shouldBe):
(isLowSurrogate):
(isHighSurrogate):
(isSurrogate):
* tests/stress/encode-decode-uri-component-surrogates.js: Added.
(shouldBe):
(toHighSurrogate):
(toLowSurrogate):
* tests/stress/encode-decode-uri-surrogates.js: Added.
(shouldBe):
(toHighSurrogate):
(toLowSurrogate):
* tests/stress/encode-decode-zero.js: Added.
(shouldBe):
* tests/stress/escape-unescape-surrogates.js: Added.
(shouldBe):
(toHighSurrogate):
(toLowSurrogate):

Source/WTF:

* wtf/Bitmap.h:
(WTF::Bitmap::size):
(WTF::WordType>::Bitmap):
(WTF::WordType>::get):
(WTF::WordType>::set):
(WTF::WordType>::testAndSet):
(WTF::WordType>::testAndClear):
(WTF::WordType>::concurrentTestAndSet):
(WTF::WordType>::concurrentTestAndClear):
(WTF::WordType>::clear):
(WTF::WordType>::clearAll):
(WTF::WordType>::nextPossiblyUnset):
(WTF::WordType>::findRunOfZeros):
(WTF::WordType>::count):
(WTF::WordType>::isEmpty):
(WTF::WordType>::isFull):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@201756 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
Source/JavaScriptCore/tests/stress/encode-decode-ascii.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/encode-decode-unicode.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/encode-decode-uri-component-surrogates.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/encode-decode-uri-surrogates.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/encode-decode-zero.js [new file with mode: 0644]
Source/JavaScriptCore/tests/stress/escape-unescape-surrogates.js [new file with mode: 0644]
Source/WTF/ChangeLog
Source/WTF/wtf/Bitmap.h