Changeset 247296 in webkit


Ignore:
Timestamp:
Jul 10, 2019 1:24:52 AM (5 years ago)
Author:
Tadeu Zagallo
Message:

Optimize join of large empty arrays
https://bugs.webkit.org/show_bug.cgi?id=199636

Reviewed by Mark Lam.

JSTests:

  • microbenchmarks/large-empty-array-join.js: Added.
  • microbenchmarks/large-empty-array-join-resolve-rope.js: Added.

Source/JavaScriptCore:

Replicate the behavior of str.repeat(count) when performing new Array(count + 1).join(str).
I added two new microbenchmarks:

  • large-empty-array-join, which does not use the result of the join and runs ~44x faster and uses ~18x less memory.
  • large-empty-array-join-resolve-rope, which uses the result of the join and runs 2x faster.

baseline diff

large-empty-array-join 2713.9698+-72.7621 61.2335+-10.4836 definitely 44.3217x faster
large-empty-array-join-resolve-string 26.5517+-0.3995 12.9309+-0.5516 definitely 2.0533x faster

large-empty-array-join memory usage with baseline (dirty):

733012 kB current_mem
756824 kB lifetime_peak

large-empty-array-join memory usage with diff (dirty):

41904 kB current_mem
41972 kB lifetime_peak

Additionally, I ran JetStream2, sunspider and v8-spider and all were neutral.

  • runtime/ArrayPrototype.cpp:

(JSC::fastJoin):

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r247194 r247296  
     12019-07-10  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        Optimize join of large empty arrays
     4        https://bugs.webkit.org/show_bug.cgi?id=199636
     5
     6        Reviewed by Mark Lam.
     7
     8        * microbenchmarks/large-empty-array-join.js: Added.
     9        * microbenchmarks/large-empty-array-join-resolve-rope.js: Added.
     10
    1112019-07-06  Michael Saboff  <msaboff@apple.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r247247 r247296  
     12019-07-10  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        Optimize join of large empty arrays
     4        https://bugs.webkit.org/show_bug.cgi?id=199636
     5
     6        Reviewed by Mark Lam.
     7
     8        Replicate the behavior of `str.repeat(count)` when performing `new Array(count + 1).join(str)`.
     9        I added two new microbenchmarks:
     10        - large-empty-array-join, which does not use the result of the join and runs ~44x faster and uses ~18x less memory.
     11        - large-empty-array-join-resolve-rope, which uses the result of the join and runs 2x faster.
     12
     13                                                    baseline                    diff
     14        large-empty-array-join                2713.9698+-72.7621    ^     61.2335+-10.4836       ^ definitely 44.3217x faster
     15        large-empty-array-join-resolve-string   26.5517+-0.3995     ^     12.9309+-0.5516        ^ definitely 2.0533x faster
     16
     17        large-empty-array-join memory usage with baseline (dirty):
     18            733012 kB current_mem
     19            756824 kB lifetime_peak
     20
     21        large-empty-array-join memory usage with diff (dirty):
     22            41904 kB current_mem
     23            41972 kB lifetime_peak
     24
     25        Additionally, I ran JetStream2, sunspider and v8-spider and all were neutral.
     26
     27        * runtime/ArrayPrototype.cpp:
     28        (JSC::fastJoin):
     29
    1302019-07-08  Keith Miller  <keith_miller@apple.com>
    231
  • trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp

    r247175 r247296  
    541541                RELEASE_AND_RETURN(scope, repeatCharacter(state, separator.characters8()[0], length - 1));
    542542            RELEASE_AND_RETURN(scope, repeatCharacter(state, separator.characters16()[0], length - 1));
     543        default:
     544            JSString* result = jsEmptyString(&state);
     545            if (length <= 1)
     546                return result;
     547
     548            JSString* operand = jsString(&vm, separator.toString());
     549            RETURN_IF_EXCEPTION(scope, { });
     550            unsigned count = length - 1;
     551            for (;;) {
     552                if (count & 1) {
     553                    result = jsString(&state, result, operand);
     554                    RETURN_IF_EXCEPTION(scope, { });
     555                }
     556                count >>= 1;
     557                if (!count)
     558                    return result;
     559                operand = jsString(&state, operand, operand);
     560                RETURN_IF_EXCEPTION(scope, { });
     561            }
    543562        }
    544563        }
Note: See TracChangeset for help on using the changeset viewer.