Andreas Kling
de424d6879
LibJS: Make Completion.[[Value]] non-optional
...
Instead, just use js_undefined() whenever the [[Value]] field is unused.
This avoids a whole bunch of presence checks.
2025-04-05 11:20:26 +02:00
Andreas Kling
c0600c4353
LibJS: Remove unused ThrowCompletionOr<T>::release... helper
2025-04-05 11:20:26 +02:00
Andreas Kling
6d8bc2b1d6
LibJS: Remove unused Completion::update_empty()
2025-04-05 11:20:26 +02:00
Andrew Kaster
8fd81c3338
LibGC+LibWeb+LibJS: Remove workaround for Swift boolean bitfield issue
...
We're using a main snapshot everywhere, so we can yeet the workaround.
2025-04-04 13:06:53 -06:00
Andrew Kaster
e4c88915ab
LibGC+LibJS+LibWeb: Add workaround for Swift boolean bitfield issue
...
This patch adds a workaround for a Swift issue where boolean bitfields
with getters and setters in SWIFT_UNSAFE_REFERENCE types are improperly
imported, causing an ICE.
2025-04-03 16:47:48 -06:00
Andreas Kling
976ccb9224
LibJS: Add fast path for Int32 values in ToBoolean
...
It's not uncommon to branch on the boolean value of integers,
so let's do that on the ToBoolean fast path.
2025-04-03 18:47:38 +02:00
Andreas Kling
8de03e8cfd
LibJS: Add fast paths in ToNumeric for booleans, null and undefined
...
These are still in the out-of-line "slow path" for ToNumeric, but
skipping all the coercion machinery can save us a lot of time.
2025-04-03 18:47:38 +02:00
Andreas Kling
ec590ef3e6
LibJS: Add builtin for Math.random()
2025-04-03 13:56:39 +02:00
Andreas Kling
714e8aec8a
LibJS: Add builtin for Math.imul()
2025-04-03 13:56:39 +02:00
Kenneth Myhra
82a2ae99c8
Everywhere: Remove DeprecatedFlyString + any remaining references to it
...
This reverts commit 7c32d1e8a5
.
2025-04-02 11:43:13 +02:00
Andreas Kling
6bb0d585e3
LibJS: Elide function wrapper for class field literal initializers
...
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
If a class field initializer is just a simple literal, we can skip
creating (and calling) a wrapper function for it entirely.
1.44x speedup on JetStream3/raytrace-private-class-fields.js
1.53x speedup on JetStream3/raytrace-public-class-fields.js
2025-04-01 23:55:20 +02:00
Andreas Kling
fd0a0e963a
LibJS: Make IteratorRecord slightly smaller
...
By reordering the members, we take this from 40 bytes to 32 bytes.
2025-04-01 20:16:39 +02:00
Andreas Kling
7c32d1e8a5
Revert "Everywhere: Remove DeprecatedFlyString + any remaining references to it"
...
This reverts commit 3131e6369f
.
Greatly regressed JavaScript benchmark performance.
2025-04-01 15:40:27 +02:00
Andreas Kling
b9c57d3122
LibJS: Use xorshift128++ PRNG for Math.random()
...
This is the same PRNG used by major browser engines, and although it's
a step down in randomness, it massively improves performance of
Math.random().
1.20x speedup on JetStream3/sync-file-system.js :^)
2025-04-01 15:16:54 +02:00
Kenneth Myhra
3131e6369f
Everywhere: Remove DeprecatedFlyString + any remaining references to it
2025-04-01 12:50:00 +02:00
Andreas Kling
a0bb31f7a0
LibJS: Make async functions & generators faster with helper types
...
Instead of returning internal generator results as ordinary JS::Objects
with properties, we now use GeneratorResult and CompletionCell which
both inherit from Cell directly and allow efficient access to state.
1.59x speedup on JetStream3/lazy-collections.js :^)
2025-04-01 02:30:42 +02:00
Andreas Kling
4dc63ddf49
LibJS: Make Optional<Utf16String> use less space
...
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
By specializing the template, we can shrink it from 16 to 8 bytes.
This makes PrimitiveString a measly 32 bytes. :^)
2025-03-30 07:16:40 +01:00
Andreas Kling
152691f9eb
LibWeb: Make RopeString subclass so PrimitiveString can be smaller
...
By moving the LHS and RHS pointers used by rope strings into a
RopeString subclass, we shrink PrimitiveString by 16 bytes. Most strings
are not rope strings, so this ends up saving quite a bit of memory.
2025-03-30 07:16:40 +01:00
Tim Ledbetter
568531f06a
Everywhere: Mark GC::Cell
derived classes as Weakable explicitly
...
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Previously, all `GC::Cell` derived classes were Weakable. Marking only
those classes that require this functionality as Weakable allows us to
reduce the memory footprint of some frequently used classes.
2025-03-29 17:36:33 -05:00
Andreas Kling
2462a6b0fa
LibJS: Use Value::to_byte_string() in fewer places
2025-03-28 12:31:40 -04:00
Andreas Kling
c71772126f
LibJS: Remove ByteString internals from PrimitiveString
...
PrimitiveString is now internally either UTF-8, UTF-16, or both.
We no longer convert them to/from ByteString anywhere, nor does VM have
a ByteString cache.
2025-03-28 12:31:40 -04:00
Andreas Kling
f5dd776b11
LibJS: Remove some irrelevant hash lookups in ESFO constructor
...
If we don't have parameter expressions, we don't need to collect
metadata about whether instantiated var names collide with parameter
names or function names, as these flags are only used in the parameter
code path.
2025-03-27 23:12:04 +00:00
Andreas Kling
c037bda455
LibJS: Use a premade shape for normal function objects
...
This avoids going through all the shape transitions when setting up the
most common form of ESFO.
This is extremely hot on Uber Eats, and this provides some relief.
2025-03-27 23:12:04 +00:00
Andreas Kling
8af5f25dd0
LibJS: Use a premade shape for normal function object prototypes
...
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This avoids one shape allocation per function instantiation.
2025-03-27 15:00:43 +00:00
Andreas Kling
dba1798de7
LibJS: Make StringOrSymbol::as_string() return a const reference
...
No need to copy the FlyString here, we can avoid the ref count churn.
2025-03-27 15:00:43 +00:00
Andreas Kling
7477002e46
LibJS: Keep parsed function parameters in a shared data structure
...
Instead of making a copy of the Vector<FunctionParameter> from the AST
every time we instantiate an ECMAScriptFunctionObject, we now keep the
parameters in a ref-counted FunctionParameters object.
This reduces memory usage, and also allows us to cache the bytecode
executables for default parameter expressions without recompiling them
for every instantiation. :^)
2025-03-27 15:00:43 +00:00
Andreas Kling
c12f8b80dc
LibJS: Add fast_is<T> helpers for all the primitive wrapper objects
...
The JS runtime is full of checks for is<NumberObject> and friends.
They were showing up in a Speedometer profile as ~1% spent in
dynamic_cast, and this basically chops that down to nothing.
2025-03-25 23:57:00 +00:00
Andreas Kling
3cc5b1a6a5
LibJS: Do a bit less stuff in PropertyKey::try_coerce_into_number()
...
The many out-of-line function calls here stood out in a profile.
2025-03-25 23:57:00 +00:00
Jess
f3a937ee76
LibJS: Fix integer overflow in target_offset
of TypedArray.set()
2025-03-25 07:45:42 +00:00
Andreas Kling
f1914893e9
LibJS+LibWeb: Remove more uses of DeprecatedFlyString
2025-03-24 22:27:17 +00:00
Andreas Kling
46a5710238
LibJS: Use FlyString in PropertyKey instead of DeprecatedFlyString
...
This required dealing with *substantial* fallout.
2025-03-24 22:27:17 +00:00
Andreas Kling
fc744e3f3f
LibJS: Add fast path for strings in Value::to_property_key()
...
If the Value is already a primitive string, we can skip all the
conversion ceremony and return a PropertyKey right away.
2025-03-24 22:27:17 +00:00
Andreas Kling
53da8893ac
LibJS: Replace PropertyKey(char[]) with PropertyKey(FlyString)
...
...and deal with the fallout.
2025-03-24 22:27:17 +00:00
Andreas Kling
d7908dbff5
LibJS: Change PropertyKey(ByteString) to PropertyKey(String)
...
...and deal with the fallout.
2025-03-24 22:27:17 +00:00
Andreas Kling
3b5032c4b1
LibJS: Remove unused StringOrSymbol constructors
2025-03-24 22:27:17 +00:00
Andreas Kling
e83a2c2369
LibJS: Prefer Value::to_string() over to_byte_string() in more places
...
We should always prefer working with String, and Value::to_string() may
even return a cached String if the Value refers to a primitive string,
but no caching occurs for ByteString.
2025-03-24 22:27:17 +00:00
Aliaksandr Kalenik
a8285f255b
LibJS: Skip allocation of temp object for primitive types in Value::get
...
Previously, `String.prototype.split()` caused the construction of a
temporary StringObject when a string primitive was passed as an
argument, solely to perform a Symbol.split lookup. This change allows
skipping that allocation by looking directly into the prototype of
primitive values.
As a result, we can avoid ~200000 StringObject allocations in a single
test from the Speedometer 2 benchmark.
Co-Authored-By: Andreas Kling <andreas@ladybird.org>
2025-03-24 20:38:11 +01:00
Andreas Kling
5f12b2a05d
LibJS: Make IteratorRecord inherit from Cell, not Object
...
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This shaves its size down from 104 bytes to 48 bytes, cutting GC
pressure caused by this type in more than half.
2025-03-22 16:59:44 -05:00
Andreas Kling
1d88c4529c
LibJS: Allow JS::Value to store a non-object Cell
...
This will allow us to refer to non-object Cells more readily in bytecode
and opens up for some nice optimizations.
2025-03-22 16:59:44 -05:00
Andreas Kling
8fcff2fa18
LibJS: Store Module::environment() as ModuleEnvironment
...
Let's use a more specific type here to allow for devirtualization.
2025-03-20 12:51:21 -05:00
Jess
12cbefbee7
LibJS+LibCrypto: Use a bitwise approach for BigInt's as*IntN methods
...
This speeds up expressions such as `BigInt.asIntN(0x4000000000000, 1n)`
(#3615 ). And those involving very large bigints.
2025-03-20 09:44:12 +01:00
Jess
92d0cd3c7c
LibJS: Make InvalidIndex
detail the full range of allowed values
2025-03-20 09:44:12 +01:00
Jess
f5a6704219
LibJS: Fix UAF in ECMAScriptFunctionObject::internal_construct
...
Currently, we create `this_argument` with
`ordinary_create_from_constructor`, then we use `arguments_list` to
build the callee_context.
The issue is we don't properly model the side-effects of
`ordinary_create_from_constructor`, if `new_target` is a proxy object
then when we `get` the prototype, arbitrary javascript can run.
This javascript could perform a function call with enough arguments to
reallocate the interpreters m_argument_values_buffer vector. This is
dangerous and leads to a use-after-free, as our stack frame maintains a
pointer to m_argument_values_buffer (`arguments_list`).
2025-03-19 10:31:00 +01:00
Timothy Flynn
780de1395b
LibJS: Merge Intl.DurationFormat style and display fields into a struct
...
This is an editorial change in the ECMA-402 spec. See:
d56d624
2025-03-18 11:47:23 -04:00
Timothy Flynn
00d00b84d3
LibJS: Ensure relevant extension keys are included in ICU locale data
...
This is a normative change in the ECMA-402 spec. See:
7508197
In our implementation, we don't have the affected AOs directly, as we
delegate to ICU. So instead, we must ensure we provide ICU a locale with
the relevant extension keys present.
2025-03-18 11:47:23 -04:00
Timothy Flynn
37b8ba96f1
LibJS: Use currency digits for NumberFormat only for standard notation
...
This is a normative change in the ECMA-402 spec. See:
9140da2
2025-03-18 11:47:23 -04:00
Timothy Flynn
96c059bf67
LibJS: Use correct enum casing in some Intl constructors
2025-03-18 11:47:23 -04:00
Timothy Flynn
532f156f4a
LibJS: Remove some single-use Intl.DurationFormat variables
...
This is an editorial change in the ECMA-402 spec. See:
4c139f1
da498c2
ed5c716
2025-03-04 07:36:10 -05:00
Timothy Flynn
1e462daa9b
LibJS: Simplify the Intl.DurationFormat GetDurationUnitOptions AO
...
This is an editorial change in the ECMA-402 spec. See:
d097048
2025-03-04 07:36:10 -05:00
Timothy Flynn
2f023c2d9c
LibJS: Simplify Intl.DurationFormat.prototype.resolvedOptions
...
This is an editorial change in the ECMA-402 spec. See:
e3d3406
2025-03-04 07:36:10 -05:00