Changeset 210735 in webkit


Ignore:
Timestamp:
Jan 13, 2017 10:30:09 AM (7 years ago)
Author:
Yusuke Suzuki
Message:

Reserve capacity for StringBuilder in unescape
https://bugs.webkit.org/show_bug.cgi?id=167008

Reviewed by Sam Weinig.

unescape function is frequently called in Kraken sha256-iterative.
This patch just reserves the capacity for the StringBuilder.

Currently, we select the length of the string for the reserved capacity.
It improves the performance 2.73%.

Benchmark report for Kraken on sakura-trick.

VMs tested:
"baseline" at /home/yusukesuzuki/dev/WebKit/WebKitBuild/untot/Release/bin/jsc
"patched" at /home/yusukesuzuki/dev/WebKit/WebKitBuild/un/Release/bin/jsc

Collected 100 samples per benchmark/VM, with 100 VM invocations per benchmark. Emitted a call to gc() between
sample measurements. Used 1 benchmark iteration per VM invocation for warm-up. Used the jsc-specific preciseTime()
function to get microsecond-level timing. Reporting benchmark execution times with 95% confidence intervals in
milliseconds.

baseline patched

stanford-crypto-sha256-iterative 51.609+-0.672 50.237+-0.860 might be 1.0273x faster

<arithmetic> 51.609+-0.672 50.237+-0.860 might be 1.0273x faster

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::globalFuncUnescape):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r210695 r210735  
     12017-01-13  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Reserve capacity for StringBuilder in unescape
     4        https://bugs.webkit.org/show_bug.cgi?id=167008
     5
     6        Reviewed by Sam Weinig.
     7
     8        `unescape` function is frequently called in Kraken sha256-iterative.
     9        This patch just reserves the capacity for the StringBuilder.
     10
     11        Currently, we select the length of the string for the reserved capacity.
     12        It improves the performance 2.73%.
     13
     14            Benchmark report for Kraken on sakura-trick.
     15
     16            VMs tested:
     17            "baseline" at /home/yusukesuzuki/dev/WebKit/WebKitBuild/untot/Release/bin/jsc
     18            "patched" at /home/yusukesuzuki/dev/WebKit/WebKitBuild/un/Release/bin/jsc
     19
     20            Collected 100 samples per benchmark/VM, with 100 VM invocations per benchmark. Emitted a call to gc() between
     21            sample measurements. Used 1 benchmark iteration per VM invocation for warm-up. Used the jsc-specific preciseTime()
     22            function to get microsecond-level timing. Reporting benchmark execution times with 95% confidence intervals in
     23            milliseconds.
     24
     25                                                       baseline                  patched
     26
     27            stanford-crypto-sha256-iterative        51.609+-0.672             50.237+-0.860           might be 1.0273x faster
     28
     29            <arithmetic>                            51.609+-0.672             50.237+-0.860           might be 1.0273x faster
     30
     31        * runtime/JSGlobalObjectFunctions.cpp:
     32        (JSC::globalFuncUnescape):
     33
    1342017-01-12  Saam Barati  <sbarati@apple.com>
    235
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp

    r210522 r210735  
    815815{
    816816    return JSValue::encode(toStringView(exec, exec->argument(0), [&] (StringView view) {
     817        unsigned k = 0;
     818        unsigned length = view.length();
     819
    817820        StringBuilder builder;
    818         int k = 0;
    819         int len = view.length();
     821        builder.reserveCapacity(length);
    820822
    821823        if (view.is8Bit()) {
    822824            const LChar* characters = view.characters8();
    823825            LChar convertedLChar;
    824             while (k < len) {
     826            while (k < length) {
    825827                const LChar* c = characters + k;
    826                 if (c[0] == '%' && k <= len - 6 && c[1] == 'u') {
     828                if (c[0] == '%' && k <= length - 6 && c[1] == 'u') {
    827829                    if (isASCIIHexDigit(c[2]) && isASCIIHexDigit(c[3]) && isASCIIHexDigit(c[4]) && isASCIIHexDigit(c[5])) {
    828830                        builder.append(Lexer<UChar>::convertUnicode(c[2], c[3], c[4], c[5]));
     
    830832                        continue;
    831833                    }
    832                 } else if (c[0] == '%' && k <= len - 3 && isASCIIHexDigit(c[1]) && isASCIIHexDigit(c[2])) {
     834                } else if (c[0] == '%' && k <= length - 3 && isASCIIHexDigit(c[1]) && isASCIIHexDigit(c[2])) {
    833835                    convertedLChar = LChar(Lexer<LChar>::convertHex(c[1], c[2]));
    834836                    c = &convertedLChar;
     
    841843            const UChar* characters = view.characters16();
    842844
    843             while (k < len) {
     845            while (k < length) {
    844846                const UChar* c = characters + k;
    845847                UChar convertedUChar;
    846                 if (c[0] == '%' && k <= len - 6 && c[1] == 'u') {
     848                if (c[0] == '%' && k <= length - 6 && c[1] == 'u') {
    847849                    if (isASCIIHexDigit(c[2]) && isASCIIHexDigit(c[3]) && isASCIIHexDigit(c[4]) && isASCIIHexDigit(c[5])) {
    848850                        convertedUChar = Lexer<UChar>::convertUnicode(c[2], c[3], c[4], c[5]);
     
    850852                        k += 5;
    851853                    }
    852                 } else if (c[0] == '%' && k <= len - 3 && isASCIIHexDigit(c[1]) && isASCIIHexDigit(c[2])) {
     854                } else if (c[0] == '%' && k <= length - 3 && isASCIIHexDigit(c[1]) && isASCIIHexDigit(c[2])) {
    853855                    convertedUChar = UChar(Lexer<UChar>::convertHex(c[1], c[2]));
    854856                    c = &convertedUChar;
Note: See TracChangeset for help on using the changeset viewer.