JavaScriptCore (JSC) is the JavaScript engine used by Safari, all iOS browsers, and Bun. Its Riptide garbage collector takes a different path from V8: objects never move, and much of the collector's design follows from that constraint. section 9.3
Riptide performs most marking on background threads while application code continues. Write barriers can force the collector to revisit old objects; sustained mutation may create a death spiral. A space-time scheduler responds by spending progressively more CPU on collection as allocations consume headroom, eventually pausing the application if necessary. Eden collections usually complete with pauses under a millisecond. section 9.3.4
JSC also avoids eager sweeping through logical versioning. A global version invalidates block metadata lazily, so dead blocks are reclaimed when allocation or marking needs them. This can delay cleanup of native resources attached to dead JavaScript objects, although a background incremental sweeper mitigates the delay. section 9.3.5
The old-object mutation trap
An in-memory sessions Map can retain long-lived session objects while each request assigns freshly allocated request data, headers, and history arrays. This combination of allocation and old-generation mutation can increase revisit work and trigger throttling in JSC. section 9.3.4
const sessions = new Map(); #A
function handleRequest(req) {
let session = sessions.get(req.sessionId);
if (!session) {
session = { id: req.sessionId, created: Date.now() };
sessions.set(req.sessionId, session);
}
// Every request mutates the long-lived session object
// with fresh short-lived objects
session.lastAccess = Date.now();
session.lastRequest = { #B
url: req.url,
headers: { ...req.headers },
timestamp: Date.now(),
};
session.history = (session.history || [])
.slice(-99)
.concat([req.url]); #C
return buildResponse(req, session);
}
Trace the request handler's long-lived Map, repeated session mutation, and fresh per-request allocations. section 9.3.4
Use these rules when reasoning about JSC memory behavior:
- Control reachability rather than merely counting allocations: short-lived objects are cheaper than objects that survive. section 9.7
- Expect diagnostics to differ from V8: Bun provides CPU profiling and heap snapshots, but not all V8 garbage-collection traces or metrics. section 11.6
