Andreas Kling
0d91363742
LibJS: Remove weird fallback behavior in VM::argument/argument_count
...
If there's no running execution context, let's just error out in there
instead of returning a weird empty value.
2025-04-05 11:20:26 +02:00
Andreas Kling
ceddc8d660
LibJS: Make a bunch of functions in Environment pure virtual
2025-04-05 11:20:26 +02:00
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
Andreas Kling
41314d0460
LibJS: Remove unnecessary exception checks in bytecode dispatch
...
No need to check for exceptions after instructions that cannot throw.
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
Jess
83e46b3728
LibRegex: Fix crash when parse result exceeds max cache size
...
Before, If the cache was empty we would try and evict non-existant
entries and crash. So the fix is to make sure that we don't saturate
the cache with a single parse result.
2025-04-04 16:10:25 +02:00
R-Goc
28d5d982ce
Everywhere: Remove unused private fields
...
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, 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 (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
This commit removes the -Wno-unusued-private-field flag, thus
reenabling the warning. Unused field were either removed or marked
[[maybe_unused]] when unsure.
2025-04-04 12:40:07 +02: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
3169747989
LibJS: Emit PutById instead of PutByValue when key is string literal
...
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 (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
Build Dev Container Image / build (push) Has been cancelled
Basically convert o["foo"]=x into o.foo=x when emitting bytecode.
These are effectively the same thing, and the latter format opts
into using an inline cache for the property lookups.
2025-04-03 18:47:38 +02:00
Andreas Kling
4426c50a18
LibJS: Emit GetById instead of GetByValue when key is string literal
...
Basically convert o["foo"] into o.foo when emitting bytecode. These are
effectively the same thing, and the latter format opts into using an
inline cache for the property lookups.
2025-04-03 18:47:38 +02: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
cba80580e2
Revert "LibJS: Avoid calling generic Instruction::length() during dispatch"
...
This reverts commit 8f2ee01e6f
.
Speculative revert, as this appears to severely regress performance on
our JS benchmark runner.
2025-04-03 15:09:49 +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
Andreas Kling
8f2ee01e6f
LibJS: Avoid calling generic Instruction::length() during dispatch
...
Since we know the exact type, we can avoid calling the generic lookup
function that branches on instruction type.
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
Lucien Fiorini
f72d87931f
LibJS: Reduce Mov instructions by using preferred destinations
2025-03-28 11:21:12 +00:00
Lucien Fiorini
5707076b9e
LibJS: Optimize away Mov instructions when the source is the destination
2025-03-28 11:21:12 +00: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
5ea45da15f
LibJS: Store NewObject result directly in preferred dst if possible
...
This avoids a Mov after every object literal.
2025-03-27 19:50:13 +00:00
Andreas Kling
900f209b34
LibJS: Make Optional<Operand> use less space
...
Shrink these down from 12 bytes to 8 bytes, which helps make many
bytecode instructions smaller.
2025-03-27 19:50:13 +00:00
Andreas Kling
a29d820f87
LibJS: Make Optional<IdentifierTableIndex> use less space
...
We can use the index's invalid state to signal an empty optional.
This makes Optional<IdentifierTableIndex> 4 bytes instead of 8,
shrinking every bytecode instruction that uses these.
2025-03-27 19:50:13 +00:00
Andreas Kling
904beef6d2
LibJS: Put newly instantiated functions into locals more efficiently
...
- Don't allocate a separate register, store directly into the local.
- Mark the local as initialized to avoid emitting TDZ checks.
2025-03-27 19:50:13 +00:00
Andreas Kling
6c70dc5f09
LibJS: Create FunctionParameters earlier in the parser
...
This avoids making multiple copies of the Vector<FunctionParameter> in
the parser.
2025-03-27 19:50:13 +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
Lucien Fiorini
6b6e13e28c
LibJS: Avoid emptying the return value register in try/finally
...
This works because at the end of the finally chunk, a
ContinuePendingUnwind is generated which copies the saved return value
register into the return value register. In cases where
ContinuePendingUnwind is not generated such as when there is a break
statement in the finally block, the fonction will return undefined which
is consistent with V8 and SpiderMonkey.
2025-03-27 12:18:30 +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
Andreas Kling
202cbe7df6
LibJS: Constant-fold unary expressions
...
!0 and !1 are very common patterns in minified JavaScript, and we should
figure out that they're constants. :^)
2025-03-25 19:14:12 +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