Commit graph

13 commits

Author SHA1 Message Date
Mike Aizatsky
19cd8b7839 capnp update 2026-11-13 14:46:51 -08:00
Gyeongjae Choi
45f1885bcc Clean up Python pool-related codes and remove emscriptenSetup from Pyodide bundle 2026-11-13 06:01:54 +00:00
Gyeongjae Choi
69ae87665a Relocate files that are used for the Pyodide bundle 2026-11-13 04:44:59 +00:00
Workers DevProd
5746b1040f update dependencies to latest version 2026-11-09 15:21:51 -05:00
Nathan Whitaker
b8061a3139
Release Rust JSG Rc and Weak under their isolate's lock
The reference counts behind a jsg::Rc (the std::rc::Rc of the resource and
the kj::Rc of its Wrappable) and a jsg::Weak (the std::rc::Weak) are not
atomic; the isolate lock is what serializes their updates. Yet an Rc or Weak
can be dropped without the lock, for example by C++ code that owns the Rust
object holding it. Dropping an Rc then did a kj::addRef to hand
maybeDeferDestruction an Own, and dropped the std::rc::Rc and the KjRc at
once: three unsynchronized updates racing with the thread that holds the lock.
A Weak dropped its std::rc::Weak at once. And a resource that had never been
wrapped had no isolate, so maybeDeferDestruction released it at once too.

Rc and Weak now keep the IsolateState of the isolate their resource was
created in, which already queues the handles of Globals and TracedGlobals
dropped without the lock. Under the lock, a drop releases the reference at
once, as before. Without it, the drop moves the parts into the state's queue
without touching any count, and the next IsolateBase::Lock releases them:
removeStrongRef if the Rc still counts as strong, then the KjRc and the
std::rc::Rc. Realm::drop releases what is still queued before closing the
state. After that, until the isolate is disposed, the isolate still detaches
wrappers and destroys the CppgcShims that own Wrappables, and no thread can
ask whether it holds the lock of an isolate that may already be disposed, so
drops are kept until the dispose hook releases them. Those releases, and
later ones, only give back the counts: no wrapper is left to update, and an
unwrapped Wrappable may still point to the disposed isolate, since detaching
a strongly held parent's wrapper makes its references strong again, which
records the isolate in the children, and clearWrappers only clears wrapped
Wrappables. No lock serializes them, so they still go through the queue,
which one thread at a time drains. wrappable_remove_strong_ref now just
calls removeStrongRef.

To know its isolate before it is wrapped, a resource now takes it at
creation: Rc::new takes a Lock, like C++ js.alloc<T>(). Wrapping a resource
in an isolate other than the one it was created in panics, as wrapping one
that already has a wrapper in another isolate did. The jsg-bench native
lifetime and memory cases create their resources under a lock accordingly.

Each Rc is 8 bytes larger (48 bytes) for its Arc<IsolateState>, and so is
each Weak (24 bytes). In jsg-bench's native-memory case, where each Node
resource holds an Rc field, that is 256 instead of 232 bytes per resource,
since the field also moves the resource into the next malloc size class.
Clones and drops got faster despite the Arc's atomic count, since a drop no
longer adds a kj::Rc reference and builds a RefToDelete. Medians of five
processes of native/lifetime, in ns per resource created and dropped, with
--config=benchmark on an Apple M5 Pro (the benchmark now runs under an
isolate lock):

  clones   before   after
  0        35.4     33.9
  1        47.6     44.0
  16      216.0    177.8

The C++ cases measured 3-7% slower in the same runs.

This changes no API exposed to Workers.
2026-11-05 14:02:01 -08:00
Workers DevProd
b3e0510b59 update dependencies to latest version 2026-11-04 18:57:07 +00:00
James M Snell
54e34e2e4d Perf improvements to ts-streams impl
Using a context extension for the pseudo-globals
injected into the per-isolate bootstrap is rather
expensive and difficult to v8 to optimize. Using
injected arguments is faster. Also, avoiding using
__proto__: null ensures that objects are created
in a fast properties mode.
2026-11-02 22:49:49 +00:00
Felix Hanau
83d02c8caa
Merge pull request #7131 from cloudflare/felix/082626-clang-tidy-23
[build] Update to clang-tidy 23
2026-10-30 14:28:45 -04:00
Felix Hanau
a8dd9cee9d [build] Don't keep unrelated rust binaries around for rustfmt
This reduces retained disk usage by 150MB, which adds up if there are several
checkouts of workerd
2026-10-29 12:26:34 -04:00
Felix Hanau
5fec441dd7 [build] Update rules_rust 2026-10-29 12:26:31 -04:00
Bartek Iwańczuk
fd0a66dc9b
[EW-11138] Leave what JavaScript setters throw pending in Rust JSG (#7975)
Fixes EW-11138. `Object::set` and `Array::set` can run JavaScript (a
setter on the object or its prototype chain, or a Proxy trap), but
their shims used `jsg::check()` and were not declared as returning
`Result`, so what JavaScript threw became a Rust panic, which
terminates execution.

- `Object::set` and `Array::set` return `jsg::Result<()>` and go
  through `call_into_js()`. Their shims catch nothing and leave the
  exception pending, so the error is one for which `is_pending()` is
  true, and they run nothing while execution is terminating.
  `Array::set` takes V8's `u32` index instead of truncating a
  `usize`.
- Converting a `Vec` to JavaScript builds the array from its elements
  with `Array::with_elements` (`v8::Array::New(isolate, elements,
  length)`), as C++ JSG does at every compatibility date, so no
  setter on `Array.prototype` runs. It stops at the first element
  whose conversion fails.
- A `#[jsg_struct]` follows C++ JSG's `fast_jsg_struct` flag (from
  2025-12-03). With it, `Object::with_data_properties` defines the
  fields with `CreateDataProperty()`, as C++ JSG's DictionaryTemplate
  does: no JavaScript runs, and an absent optional field is an own
  property whose value is `undefined`. Without it, the fields are set
  one by one with `Object::set`, as C++ JSG's `Set()` path does: an
  absent optional field is omitted, a setter on `Object.prototype`
  runs, and what it throws is passed on through the fallible `ToJS`.
  `Object::with_data_properties` returns the error from interning a
  key that is too long rather than panicking.
- The Node.js exception helpers in `node-exceptions` pass on what
  setting `code`, `syscall`, `path` and `dest` throws. The C++ caller
  throws `JsExceptionThrown` for it, as `JsObject::set` does.
- `local_array_get`, which nothing called, is removed.

This removes three `jsg::check` uses from `ffi.c++` and adds no C++
JSG; `cpp-jsg-allowlist.txt` lowers its count from 4 to 1.

Behavior matches C++ JSG at every compatibility date. The only
observable change is where a script defines a setter on
`Array.prototype` or `Object.prototype`. Previously, a setter that
threw during a conversion or a `set` panicked and terminated the
Worker. Now what it throws reaches the caller, and conversions run
the same setters C++ JSG runs. For the Rust-converted structs in
`node:dns` (`CaaRecord` and `NaptrRecord`, from `resolveCaa()` and
`resolveNaptr()`), that means a setter on `Object.prototype` for a
field runs without `fast_jsg_struct` and doesn't run with it, as for
C++ JSG structs.
2026-10-27 20:47:21 +01:00
Dan Lapid
b929d94219 Refresh MODULE.bazel.lock
14179241b updated dependencies (brotli 1.2.1, aspect_rules_js 3.5.2,
rules_cc 0.2.27, rules_foreign_cc 0.17.0, rules_python 2.4.5, ...)
without refreshing the lockfile, so every checkout re-evaluated the
module extensions and rewrote it. This is the lockfile Bazel writes for
the current MODULE.bazel files; `bazel build --lockfile_mode=error
--nobuild //...` accepts it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-26 23:01:25 -04:00
Dan Lapid
e0076b603a Commit MODULE.bazel.lock and crate_universe's lockfile
With MODULE.bazel.lock ignored, every fresh checkout, CI's included,
re-evaluated every module extension: crate_universe, pip, npm, Go and
Node SDKs, the LLVM toolchain. Committed, a checkout whose MODULE.bazel
files match the lock skips evaluation and goes straight to the
repositories the build needs. Each extension's entry is
host-independent, since every extension declares its repositories for
all platforms, so one lockfile serves Linux, macOS and Windows;
`bazel build --lockfile_mode=error --nobuild //...` accepts it. Bazel
keeps the lock current by itself (the default --lockfile_mode=update),
so a change to MODULE.bazel commits the refreshed lockfile with it, and
a stale one costs only the re-evaluation it would have cost before.

Without a lockfile of its own, crate_universe's from_cargo ran
cargo-bazel to resolve deps/rust/Cargo.lock into Bazel repositories
every time its extension was evaluated: 27s of every analysis locally
and 41-48s in CI. deps/rust/cargo-bazel-lock.json pins the resolution,
which brings that to about 1s. It has to follow Cargo.toml and
Cargo.lock, and Bazel stops with a digest mismatch when it doesn't.
`just update-rust` and the dependency updater update both through
crate_universe (CARGO_BAZEL_REPIN=all, or a package's name), and the
updater commits both lockfiles with its updates; after editing either
Cargo file by hand, repin with
`bazel fetch --repo_env=CARGO_BAZEL_REPIN=1 --repo=@crates_vendor`. Repinning the
committed Cargo.lock reproduces the file byte for byte.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-26 19:36:08 -04:00