Commit 159ff24
perf(server): avoid
Using `delete` on object properties changes the V8 hidden class (object
"shape"), forcing the engine into dictionary/slow-property mode and
disabling inline caching for all subsequent property accesses on that
object. TanStack observed >50% CPU time reduction in affected methods
after switching to `undefined` assignment.
This commit makes three targeted changes in the SSR request hot path:
1. **`parsedUrl.query` clear-and-replace** (base-server.ts): Instead of
loop-deleting every key then using `Object.assign`, reassign
`parsedUrl.query` to a fresh object. This avoids N shape transitions
and is semantically equivalent since `parsedUrl.query` is accessed
via the property, not by captured reference.
2. **`req.headers[NEXT_URL]` removal** (base-server.ts): Use
`= undefined` instead of `delete`. Downstream code accesses this
header by value (`headers[NEXT_URL]`), never with the `in` operator,
so `undefined` is semantically equivalent.
3. **`removeRequestMeta`** (request-meta.ts): Use `= undefined` instead
of `delete`. All consumers use `getRequestMeta(req, key)` which
returns `meta[key]` — `undefined` is indistinguishable from a
missing key. The request meta object persists for the entire request
lifetime, so preserving its shape benefits all downstream accesses.
Several other `delete` sites were analyzed and intentionally left
unchanged because they affect objects that are later serialized via
`querystring.stringify` or `url.format`, where `undefined` values
would leak as empty query parameters (e.g., `_rsc=`).
Reference: https://tanstack.com/blog/tanstack-start-v1-5x-faster-ssr
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>delete on hot-path objects to preserve V8 hidden classes1 parent 196ed2b commit 159ff24
2 files changed
+12
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1541 | 1541 | | |
1542 | 1542 | | |
1543 | 1543 | | |
1544 | | - | |
1545 | | - | |
1546 | | - | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
1547 | 1548 | | |
1548 | | - | |
1549 | | - | |
1550 | | - | |
1551 | | - | |
| 1549 | + | |
1552 | 1550 | | |
1553 | 1551 | | |
1554 | 1552 | | |
| |||
2018 | 2016 | | |
2019 | 2017 | | |
2020 | 2018 | | |
2021 | | - | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
2022 | 2022 | | |
2023 | 2023 | | |
2024 | 2024 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
375 | | - | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
376 | 379 | | |
377 | 380 | | |
378 | 381 | | |
| |||
0 commit comments