Skip to content

Various optimizations and some cleanup - #38

Merged
tschneidereit merged 6 commits into
mainfrom
optimizations
Sep 24, 2026
Merged

tschneidereit merged 6 commits into
mainfrom
optimizations

Conversation

@tschneidereit

Copy link
Copy Markdown
Member

This is a bit of an assortment of changes that don't fit a clear pattern, but are individually too small to PR. I'll land them as separate commits, so they don't get bundled up into an incoherent mess.

This was a short-lived test bed for the platform part of HTTP support, now made redundant by `fetch` and `FetchEvent` support.
And remove some that aren't in use anymore.
Iterating a `Headers` object ran `sort and combine` over the whole list on
every step. `CachedHeaderList` wraps the list and computes that form once,
on first use, and every mutable access to the list drops it again.
The GC schedules collections from the bytes reported to it, and a body's
byte source lives in Rust memory outside the GC heap. Objects holding large
bodies were invisible to the heap-growth heuristics, so building many of
them grew memory until the process ran out.

`js::gc::AssociatedMemory` wraps `JS::AddAssociatedMemory`. That accounting
is keyed by the object's address and a compacting GC relocates tenured
objects, so every call takes the object's current address: a rooted handle
while the object is alive, and the finalizer's argument once it is being
finalized. `#[destructor]` therefore takes an optional second parameter
holding the object being finalized, and a class declared with `extends`
runs its parent's destructor after its own.

`Request` and `Response` hold an `AssociatedMemory`, re-sync it wherever the
byte source is set, taken, cloned or dropped, and release it from their
destructors. One test builds bodies in a loop and checks that collections
happen. Another relocates accounted objects with a compacting GC and checks
that both the update and the release go through the new address.
The global resolves standard classes lazily, on first use. An instance
restored from a snapshot paid for each one in the first request that
touched it. `pre_initialize` now defines them all before the snapshot.
@tschneidereit
tschneidereit merged commit 48618bf into main Sep 24, 2026
10 checks passed
@tschneidereit
tschneidereit deleted the optimizations branch September 24, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant