Closed Bug 1941001 Opened 1 month ago Closed 1 month ago

Move some TypedArray builtins from self-hosted code to C++

Categories

(Core :: JavaScript: Standard Library, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
136 Branch
Tracking Status
firefox136 --- fixed

People

(Reporter: anba, Assigned: anba)

References

Details

Attachments

(12 files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

Bug 1939135 spends a large amount of time in GC code, because the website calls TypedArrayJoin, which creates many ropes of small inline strings. Moving TypedArrayJoin to C++ to make it more similar to js::array_join avoids creating many string ropes.

In addition to TypedArrayJoin, let's also move the following functions to C++:

  • TypedArrayIndexOf (can use SIMD when in C++)
  • TypedArrayLastIndexOf
  • TypedArrayIncludes (can use SIMD when in C++)
  • TypedArrayFill (can use memset when in C++)
  • TypedArrayReverse
  • TypedArrayToReversed
  • TypedArrayWith

Using C++ improves performance in many cases and also avoids going megamorphic when self-hosted built-ins are called with different TypedArray kinds.

The implementation loosely follows js::array_join.

Shared memory can't use SIMD, because data-races lead to UB in C++.

Delegates to TypedArrayIndexOf for SIMD optimised code paths, unless
searching for NaN.

As an optimisation, use std::memset resp. AtomicOperations::memsetSafeWhenRacy
if possible.

This removes some duplicate code and also adds a fast-path for the common case
when the input is an Int32 value.

Prefer (Un)SharedOps to match the other code in this file.

Severity: -- → N/A
Priority: -- → P2
Pushed by andre.bargull@gmail.com: https://hg.mozilla.org/integration/autoland/rev/c6ca49e9a2f4 Part 1: Move TypedArrayJoin to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/36f8e84f8262 Part 2: Support uint32_t in SIMD memchr. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/a3816bfd8968 Part 3: Move TypedArrayIndexOf to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/e9a0f6cfb80d Part 4: Move TypedArrayLastIndexOf to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/9d93f1251e11 Part 5: Move TypedArrayIncludes to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/1f873198a368 Part 6: Move TypedArrayFill to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/11555d3ee9e6 Part 7: Move TypedArrayReverse to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/8ee4080340a3 Part 8: Add common function for relative integer computation. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/59af1cd4e354 Part 9: Move TypedArrayToReversed to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/12990bf5b579 Part 10: Move TypedArrayWith to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/8de4edbed18a Part 11: Use (Un)SharedOps in TypedArray::copyWithin. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/5525330aa020 Part 12: Remove no longer used GetTypedArrayKind. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/4837b488b543 apply code formatting via Lando

(In reply to Sandor Molnar[:smolnar] from comment #14)

Backed out for causing build bustages

Thanks. Forgot to add the SIMD fallback implementation for non-x86 targets.

Flags: needinfo?(andrebargull)
Pushed by andre.bargull@gmail.com: https://hg.mozilla.org/integration/autoland/rev/d1d73f454db6 Part 1: Move TypedArrayJoin to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/e8cf9870c8a0 Part 2: Support uint32_t in SIMD memchr. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/b3ce1da10762 Part 3: Move TypedArrayIndexOf to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/1a7fab3a784a Part 4: Move TypedArrayLastIndexOf to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/b35b2fd58724 Part 5: Move TypedArrayIncludes to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/419414519c43 Part 6: Move TypedArrayFill to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/9700e2704fff Part 7: Move TypedArrayReverse to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/829b0986166e Part 8: Add common function for relative integer computation. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/b8709ae86ced Part 9: Move TypedArrayToReversed to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/a0b02649824d Part 10: Move TypedArrayWith to C++. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/5a3393e105c6 Part 11: Use (Un)SharedOps in TypedArray::copyWithin. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/922d4aaa9028 Part 12: Remove no longer used GetTypedArrayKind. r=spidermonkey-reviewers,jandem https://hg.mozilla.org/integration/autoland/rev/3a6b0cf19d8f apply code formatting via Lando

Just a FYI: This increased the XUL size by 56KB on Windows. This metric is not tracked directly for perf, so no action is expected.

(In reply to Mayank Bansal from comment #17)

Just a FYI: This increased the XUL size by 56KB on Windows. This metric is not tracked directly for perf, so no action is expected.

Interesting. I guess we could try if sharing code improve this. For example we instantiate TypedArrayReverse 24 times (= 12 (each element type) * 2 (shared and unshared)). If we instead only instantiate one version per element-width, we'd use only 4 * 2 = 8 TypedArrayReverse functions.

Regressions: 1942592
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: