Commit b31680f
fix(runtime): reduce memory retention after web worker termination (#32617)
## Summary
Addresses #26058 — Web Workers use significantly more RSS than Chrome,
and terminating them doesn't release the memory back to the OS.
Two targeted changes:
- **Call `malloc_trim(0)` on Linux after each worker thread exits.**
When a worker's V8 isolate and tokio runtime are dropped, glibc's
allocator holds onto the fragmented heap pages rather than returning
them to the OS. This explicitly asks glibc to release them. Follows the
same pattern already used in the SIGUSR2 memory trim handler
(`runtime/worker.rs:81`).
- **Remove the delayed termination hack entirely.** The 2-second timer
that spawned threads/tasks to force-terminate workers is no longer
needed — the upstream V8 issue that required it has been fixed. Workers
now terminate cooperatively via the termination signal and event loop
wakeup, which also eliminates the ~100 lingering OS threads during rapid
worker churn.
### What this doesn't fix
- The ~7-8MB per-isolate overhead from V8's lack of shared read-only
heap (upstream V8 issue)
- macOS/Windows RSS behavior (`malloc_trim` is Linux-only)
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 7698bcc commit b31680f
2 files changed
+18
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
273 | 286 | | |
274 | 287 | | |
275 | 288 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | | - | |
273 | 272 | | |
274 | | - | |
275 | 273 | | |
276 | 274 | | |
277 | 275 | | |
| |||
280 | 278 | | |
281 | 279 | | |
282 | 280 | | |
283 | | - | |
284 | 281 | | |
285 | | - | |
286 | 282 | | |
287 | 283 | | |
288 | 284 | | |
| |||
299 | 295 | | |
300 | 296 | | |
301 | 297 | | |
302 | | - | |
303 | 298 | | |
304 | | - | |
305 | 299 | | |
306 | 300 | | |
307 | 301 | | |
| |||
315 | 309 | | |
316 | 310 | | |
317 | 311 | | |
318 | | - | |
| 312 | + | |
319 | 313 | | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | 314 | | |
325 | 315 | | |
326 | 316 | | |
327 | 317 | | |
328 | 318 | | |
329 | | - | |
| 319 | + | |
330 | 320 | | |
331 | 321 | | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | 322 | | |
349 | 323 | | |
350 | 324 | | |
| |||
363 | 337 | | |
364 | 338 | | |
365 | 339 | | |
366 | | - | |
| 340 | + | |
367 | 341 | | |
368 | | - | |
| 342 | + | |
369 | 343 | | |
370 | 344 | | |
371 | 345 | | |
| |||
374 | 348 | | |
375 | 349 | | |
376 | 350 | | |
377 | | - | |
378 | 351 | | |
379 | | - | |
380 | 352 | | |
381 | 353 | | |
382 | 354 | | |
| |||
0 commit comments