Skip to content

Fix key accounting in byte-budgeted LRUs - #96187

Draft
marcoshernanz wants to merge 3 commits into
canaryfrom
codex/fix-memory-leaks-94890-94919-95094
Draft

marcoshernanz wants to merge 3 commits into
canaryfrom
codex/fix-memory-leaks-94890-94919-95094

Conversation

@marcoshernanz

@marcoshernanz marcoshernanz commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

What?

Include retained string keys in the size of byte-budgeted in-memory LRUs.

LRUCache now passes the key to custom size calculators, and each in-memory
byte-budgeted caller includes that key in its estimate. Count-based caches and
the disk-byte LRU are intentionally unchanged.

#94699 covers the original filesystem call site. This draft also applies the
same API change to the other byte-budgeted in-memory callers found by the
all-caller audit.

Why?

Large unique keys were effectively free. In the filesystem negative cache,
one million long misses could fit under a nominal 1 MiB budget because every
entry counted as one byte while retaining the full path.

Measurement

Exact merge-base/head comparison on a 16-vCPU, 32-GiB DevBox with Node
24.14.1. After one warmup per revision, four runs each were interleaved, with
four forced GCs per sample:

1.2M unique 200-byte keys Before After
Retained entries 1,048,576 5,242
Median heap used 342.49 MiB 8.32 MiB
Median RSS 570.84 MiB 229.82 MiB
Median elapsed time 4,236.76 ms 1,886.81 ms

Final heap and entry-count A/A ranges were zero for both revisions; final RSS
ranges were 0.55 MiB before and 1.03 MiB after. This is a 97.57% heap
reduction and a 99.50% retained-entry reduction.

Validation

  • pnpm exec turbo run build --filter=next...
  • pnpm --filter=next types
  • LRU Jest suite (26/26), focused ESLint, Prettier, and git diff --check
  • Interleaved retention benchmarks

The independent fixes for #94919 and #95094 are already covered by the smaller
#96173 and #96161, respectively, so they are intentionally excluded here.

Fixes #94890

@github-actions

github-actions Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Stats from current PR

✅ No significant changes detected

📊 All Metrics
📖 Metrics Glossary

Dev Server Metrics:

  • Listen = TCP port starts accepting connections
  • First Request = HTTP server returns successful response
  • Cold = Fresh build (no cache)
  • Warm = With cached build artifacts

Build Metrics:

  • Fresh = Clean build (no .next directory)
  • Cached = With existing .next directory

Change Thresholds:

  • Time: Changes < 50ms AND < 10%, OR < 2% are insignificant
  • Size: Changes < 1KB AND < 1% are insignificant
  • All other changes are flagged to catch regressions

⚡ Dev Server

Metric Canary PR Change Trend
Cold (Listen) 813ms 812ms ✓ ▂▁▂▁▂
Cold (Ready in log) 788ms 778ms ✓ ▂▁▁▁▁
Cold (First Request) 1.294s 1.278s ✓ ▃▁▁▁▁
Warm (Listen) 813ms 812ms ✓ ▂▁▂▁▂
Warm (Ready in log) 777ms 775ms ✓ ▂▁▁▁▂
Warm (First Request) 1.260s 1.256s ✓ ▂▁▁▁▂
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change Trend
Cold (Listen) 761ms 762ms ✓ ▁▅▅▅▁
Cold (Ready in log) 760ms 766ms ✓ ▁▄▃▃▂
Cold (First Request) 3.320s 3.321s ✓ ▁▄▂▂▂
Warm (Listen) 761ms 762ms ✓ ▁▄▁▅▄
Warm (Ready in log) 767ms 756ms ✓ ▁▃▂▃▂
Warm (First Request) 3.307s 3.289s ✓ ▁▂▂▂▂

⚡ Production Builds

Metric Canary PR Change Trend
Fresh Build 4.961s 4.923s ✓ ▃▁▂▁▃
Cached Build 4.990s 5.041s ✓ ▄▁▂▁▃
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change Trend
Fresh Build 23.408s 23.194s ✓ ▁▃▃▃▄
Cached Build 23.483s 23.402s ✓ ▁▃▃▂▄
node_modules Size 528 MB 528 MB ✓ ▁▁▁▁▁
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles
Canary PR Change
0a-p0meqxynjz.js gzip 10.3 kB N/A -
0avtke4yefj4-.js gzip 13.1 kB N/A -
0cz1d0mv5g_q7.js gzip 39.4 kB 39.4 kB ✓
0gl2iykkguh4d.js gzip 65.6 kB N/A -
0llk16ml1vb4v.js gzip 169 B N/A -
0p3o46_wsr2_o.js gzip 154 B N/A -
0pt5of3ch6d2u.js gzip 13.6 kB N/A -
0xnsdo-6y9r3k.js gzip 5.72 kB N/A -
0yi7is8u4covm.js gzip 8.77 kB N/A -
13x7w_xsyz1kg.js gzip 155 B N/A -
1elt1qium-r2m.css gzip 115 B 115 B ✓
1mgk3uqcaf-zj.js gzip 153 B N/A -
1prv-wg6jgtt2.js gzip 8.77 kB N/A -
1t47vod02e_4a.js gzip 8.75 kB N/A -
1tf1phijqlx9j.js gzip 220 B 220 B ✓
1tw002sq5bo4l.js gzip 10 kB N/A -
1vemgnqgwu6tb.js gzip 71.1 kB N/A -
1wlerik1n7zbr.js gzip 8.7 kB N/A -
2560rh2e_a8s4.js gzip 156 B N/A -
29qjgpjtp2p4b.js gzip 158 B N/A -
2a4p0ueayidsb.js gzip 155 B N/A -
2lviwqiqxm904.js gzip 3.52 kB N/A -
2pevdqjpbf3xk.js gzip 9.45 kB N/A -
2qd2anu9eizlz.js gzip 8.75 kB N/A -
2sv39ae5_8vfj.js gzip 8.81 kB N/A -
2utx6n7w65xqa.js gzip 8.7 kB N/A -
2zps1per6wm9r.js gzip 154 B N/A -
2zq1gws80ir40.js gzip 159 B N/A -
3-ukivglqkfeq.js gzip 8.78 kB N/A -
30oyryl5q4xf-.js gzip 45.2 kB N/A -
325xisqrylugu.js gzip 450 B N/A -
3961aoocb426j.js gzip 154 B N/A -
3jc9ghvds1spf.js gzip 2.29 kB N/A -
3juwkvkgvywfe.js gzip 10.6 kB N/A -
3kbove7q58uqh.js gzip 13.2 kB N/A -
3msg5ym65p0gm.js gzip 157 B N/A -
3qn7vntp30gaj.js gzip 1.47 kB N/A -
3r14vs4fuhwfd.js gzip 154 B N/A -
3u9ziwgnnaj5j.js gzip 7.4 kB N/A -
3wav-92p7x_3n.js gzip 159 B N/A -
turbopack-0-..piqo.js gzip 3.8 kB N/A -
turbopack-0j..b5x8.js gzip 3.82 kB N/A -
turbopack-0v..yhs0.js gzip 3.8 kB N/A -
turbopack-10..em3o.js gzip 3.8 kB N/A -
turbopack-12..6pt0.js gzip 3.8 kB N/A -
turbopack-1b..dbqb.js gzip 3.8 kB N/A -
turbopack-2c..7zii.js gzip 3.8 kB N/A -
turbopack-2d..xgsa.js gzip 3.8 kB N/A -
turbopack-2f..78o9.js gzip 3.8 kB N/A -
turbopack-2f..mu_6.js gzip 3.8 kB N/A -
turbopack-3-..gdef.js gzip 3.81 kB N/A -
turbopack-3h..ra5s.js gzip 3.81 kB N/A -
turbopack-3t..9_2x.js gzip 3.81 kB N/A -
turbopack-3u..wmfk.js gzip 3.78 kB N/A -
00z5q9hgk77pj.js gzip N/A 71.1 kB -
030a1njeh5b77.js gzip N/A 10 kB -
0b-mp_6p0pfc3.js gzip N/A 156 B -
0b2x8e0etci0g.js gzip N/A 157 B -
0ev_hnv3jxpfc.js gzip N/A 45.2 kB -
0ko7a5wuygdwg.js gzip N/A 158 B -
0ot0qt5np20h7.js gzip N/A 8.78 kB -
0s54zgx71aknn.js gzip N/A 158 B -
0w9fbc7peumpk.js gzip N/A 158 B -
1-zng1g6w4dpf.js gzip N/A 65.6 kB -
12m9rr7_7cexd.js gzip N/A 8.7 kB -
186r3y_rfvr0b.js gzip N/A 8.78 kB -
19v97848yrjp7.js gzip N/A 8.81 kB -
1nd_0rwgz2ozk.js gzip N/A 9.45 kB -
1oi9pltr_e10m.js gzip N/A 10.6 kB -
1rd9tzqgzsz2w.js gzip N/A 8.77 kB -
1rq1g_cwv642d.js gzip N/A 10.3 kB -
1s02_qdjk8zrj.js gzip N/A 153 B -
1uojw_uabeg93.js gzip N/A 450 B -
1w-7lusgyl81y.js gzip N/A 8.7 kB -
2-t8d8btwm08o.js gzip N/A 161 B -
21h56wdn9zddo.js gzip N/A 8.75 kB -
22kihrt4w3tzq.js gzip N/A 169 B -
24lh7-r5fnerg.js gzip N/A 156 B -
2dm6x96suml11.js gzip N/A 156 B -
2lg10omv7xu14.js gzip N/A 3.52 kB -
2ovff1533zvno.js gzip N/A 13.2 kB -
2s4z8jy0z7v93.js gzip N/A 1.46 kB -
2y6gb5bs4mnam.js gzip N/A 8.75 kB -
3_hwgducey93o.js gzip N/A 163 B -
341h71ln1jpl3.js gzip N/A 2.29 kB -
34ttpt_n7605h.js gzip N/A 5.72 kB -
36ckfq9o-ys-a.js gzip N/A 13.1 kB -
38j_hl1ifbc1t.js gzip N/A 155 B -
38n1na-4zsfpn.js gzip N/A 7.41 kB -
3vdh6_u50pu5t.js gzip N/A 13.6 kB -
41s7k-ro6g1v-.js gzip N/A 155 B -
turbopack-05..7b3f.js gzip N/A 3.81 kB -
turbopack-06..phwb.js gzip N/A 3.81 kB -
turbopack-0h..9068.js gzip N/A 3.81 kB -
turbopack-0t..c0df.js gzip N/A 3.81 kB -
turbopack-0x..s5xy.js gzip N/A 3.81 kB -
turbopack-12..tshx.js gzip N/A 3.81 kB -
turbopack-14..ec0c.js gzip N/A 3.8 kB -
turbopack-16..sui7.js gzip N/A 3.81 kB -
turbopack-2d..dsjf.js gzip N/A 3.81 kB -
turbopack-2m..0qgm.js gzip N/A 3.78 kB -
turbopack-37..hwsl.js gzip N/A 3.82 kB -
turbopack-3b..scbf.js gzip N/A 3.81 kB -
turbopack-3m..kumf.js gzip N/A 3.81 kB -
turbopack-3p..pfuc.js gzip N/A 3.81 kB -
Total 448 kB 448 kB ⚠️ +99 B

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 780 B 775 B ✓
Total 780 B 775 B ✅ -5 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 429 B 434 B 🔴 +5 B (+1%)
Total 429 B 434 B ⚠️ +5 B

📦 Webpack

Client

Main Bundles
Canary PR Change
3322-HASH.js gzip 63.8 kB N/A -
4191.HASH.js gzip 169 B N/A -
7920-HASH.js gzip 4.68 kB N/A -
9784-HASH.js gzip 5.63 kB N/A -
b1ad9f4c-HASH.js gzip 62.9 kB N/A -
framework-HASH.js gzip 59.7 kB 59.7 kB ✓
main-app-HASH.js gzip 254 B 252 B ✓
main-HASH.js gzip 40 kB 40 kB ✓
webpack-HASH.js gzip 1.68 kB 1.68 kB ✓
3577.HASH.js gzip N/A 168 B -
578-HASH.js gzip N/A 64.5 kB -
8590-HASH.js gzip N/A 5.61 kB -
9750-HASH.js gzip N/A 4.69 kB -
a8984546-HASH.js gzip N/A 62.9 kB -
Total 239 kB 239 kB ⚠️ +606 B
Polyfills
Canary PR Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB ✓
Total 39.4 kB 39.4 kB ✓
Pages
Canary PR Change
_app-HASH.js gzip 194 B 193 B ✓
_error-HASH.js gzip 181 B 182 B ✓
css-HASH.js gzip 334 B 331 B ✓
dynamic-HASH.js gzip 1.81 kB 1.81 kB ✓
edge-ssr-HASH.js gzip 255 B 253 B ✓
head-HASH.js gzip 349 B 351 B ✓
hooks-HASH.js gzip 382 B 384 B ✓
image-HASH.js gzip 581 B 582 B ✓
index-HASH.js gzip 260 B 259 B ✓
link-HASH.js gzip 2.48 kB 2.48 kB ✓
routerDirect..HASH.js gzip 317 B 318 B ✓
script-HASH.js gzip 384 B 386 B ✓
withRouter-HASH.js gzip 316 B 315 B ✓
1afbb74e6ecf..834.css gzip 106 B 106 B ✓
Total 7.95 kB 7.95 kB ⚠️ +1 B

Server

Edge SSR
Canary PR Change
edge-ssr.js gzip 128 kB 128 kB ✓
page.js gzip 288 kB 287 kB ✓
Total 416 kB 415 kB ✅ -988 B
Middleware
Canary PR Change
middleware-b..fest.js gzip 620 B 615 B ✓
middleware-r..fest.js gzip 156 B 156 B ✓
middleware.js gzip 45.5 kB 45.2 kB ✓
edge-runtime..pack.js gzip 842 B 842 B ✓
Total 47.1 kB 46.8 kB ✅ -350 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 718 B 718 B ✓
Total 718 B 718 B ✓
Build Cache
Canary PR Change
0.pack gzip 4.6 MB 4.6 MB ✓
index.pack gzip 122 kB 123 kB ✓
index.pack.old gzip 121 kB 122 kB ✓
Total 4.84 MB 4.84 MB ⚠️ +139 B

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 366 kB 366 kB ✓
app-page-exp..prod.js gzip 202 kB 202 kB ✓
app-page-tur...dev.js gzip 366 kB 366 kB ✓
app-page-tur..prod.js gzip 202 kB 202 kB ✓
app-page-tur...dev.js gzip 362 kB 362 kB ✓
app-page-tur..prod.js gzip 200 kB 200 kB ✓
app-page.run...dev.js gzip 363 kB 363 kB ✓
app-page.run..prod.js gzip 200 kB 200 kB ✓
app-route-ex...dev.js gzip 81.8 kB 81.8 kB ✓
app-route-ex..prod.js gzip 55.6 kB 55.6 kB ✓
app-route-tu...dev.js gzip 81.8 kB 81.8 kB ✓
app-route-tu..prod.js gzip 55.6 kB 55.6 kB ✓
app-route-tu...dev.js gzip 81.4 kB 81.4 kB ✓
app-route-tu..prod.js gzip 55.4 kB 55.4 kB ✓
app-route.ru...dev.js gzip 81.4 kB 81.4 kB ✓
app-route.ru..prod.js gzip 55.4 kB 55.4 kB ✓
dist_client_...dev.js gzip 324 B 324 B ✓
dist_client_...dev.js gzip 326 B 326 B ✓
dist_client_...dev.js gzip 318 B 318 B ✓
dist_client_...dev.js gzip 317 B 317 B ✓
pages-api-tu...dev.js gzip 45.4 kB 45.4 kB ✓
pages-api-tu..prod.js gzip 34.1 kB 34.1 kB ✓
pages-api.ru...dev.js gzip 45.4 kB 45.4 kB ✓
pages-api.ru..prod.js gzip 34.1 kB 34.1 kB ✓
pages-turbo....dev.js gzip 54.9 kB 54.9 kB ✓
pages-turbo...prod.js gzip 39.7 kB 39.7 kB ✓
pages.runtim...dev.js gzip 54.8 kB 54.9 kB ✓
pages.runtim..prod.js gzip 39.7 kB 39.7 kB ✓
server.runti..prod.js gzip 68 kB 68 kB ✓
use-cache-pr...dev.js gzip 71.6 kB 71.6 kB ✓
use-cache-pr...dev.js gzip 71.6 kB 71.7 kB ✓
use-cache-pr...dev.js gzip 70 kB 70 kB ✓
use-cache-pr...dev.js gzip 69.9 kB 70 kB ✓
Total 3.51 MB 3.51 MB ⚠️ +248 B
📝 Changed Files (29 files)

Files with changes:

  • app-page-exp..ntime.dev.js
  • app-page-exp..time.prod.js
  • app-page-tur..ntime.dev.js
  • app-page-tur..time.prod.js
  • app-page-tur..ntime.dev.js
  • app-page-tur..time.prod.js
  • app-page.runtime.dev.js
  • app-page.runtime.prod.js
  • app-route-ex..ntime.dev.js
  • app-route-ex..time.prod.js
  • app-route-tu..ntime.dev.js
  • app-route-tu..time.prod.js
  • app-route-tu..ntime.dev.js
  • app-route-tu..time.prod.js
  • app-route.runtime.dev.js
  • app-route.ru..time.prod.js
  • pages-api-tu..ntime.dev.js
  • pages-api-tu..time.prod.js
  • pages-api.runtime.dev.js
  • pages-api.ru..time.prod.js
  • ... and 9 more
View diffs
app-page-exp..ntime.dev.js

Diff too large to display

app-page-exp..time.prod.js

Diff too large to display

app-page-tur..ntime.dev.js

Diff too large to display

app-page-tur..time.prod.js

Diff too large to display

app-page-tur..ntime.dev.js

Diff too large to display

app-page-tur..time.prod.js

Diff too large to display

app-page.runtime.dev.js

Diff too large to display

app-page.runtime.prod.js

Diff too large to display

app-route-ex..ntime.dev.js

Diff too large to display

app-route-ex..time.prod.js

Diff too large to display

app-route-tu..ntime.dev.js

Diff too large to display

app-route-tu..time.prod.js

Diff too large to display

app-route-tu..ntime.dev.js

Diff too large to display

app-route-tu..time.prod.js

Diff too large to display

app-route.runtime.dev.js

Diff too large to display

app-route.ru..time.prod.js

Diff too large to display

pages-api-tu..ntime.dev.js

Diff too large to display

pages-api-tu..time.prod.js

Diff too large to display

pages-api.runtime.dev.js

Diff too large to display

pages-api.ru..time.prod.js

Diff too large to display

pages-turbo...ntime.dev.js

Diff too large to display

pages-turbo...time.prod.js

Diff too large to display

pages.runtime.dev.js

Diff too large to display

pages.runtime.prod.js

Diff too large to display

server.runtime.prod.js

Diff too large to display

use-cache-pr..ntime.dev.js

Diff too large to display

use-cache-pr..ntime.dev.js

Diff too large to display

use-cache-pr..ntime.dev.js

Diff too large to display

use-cache-pr..ntime.dev.js

Diff too large to display

📎 Tarball URL
https://vercel-packages.vercel.app/next/commits/0b6e43c8e8cd465c1fae7c4857e862bf272f59d4/next

Commit: 0b6e43c

@github-actions

github-actions Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 0b6e43c

@marcoshernanz marcoshernanz changed the title fix server memory leaks in caches, compression, and Edge timers fix memory accounting and Edge timeout retention Jul 25, 2026
@marcoshernanz marcoshernanz changed the title fix memory accounting and Edge timeout retention Fix key accounting in byte-budgeted LRUs Jul 25, 2026
patelzz007 pushed a commit to patelzz007/next.js that referenced this pull request Jul 27, 2026
Fixes vercel#94890

Adopted from vercel#96187 and vercel#94699, with both authors credited on the
commit.

The router server keeps an in-memory cache that maps request URL paths
to what they resolve to: a page, a static file, or nothing.

It's bounded by a size budget, but the size of each entry was computed
from the cached value only. The URL string used as the key was free, and
"resolves to nothing" entries counted as size 1. So a long-lived server
receiving many unique URLs — bot crawls, long slugs, `/order/:id`-style
traffic — could accumulate up to ~1M URL strings while the cache
believed it was within budget.

That looks like a slow memory leak that tracks how many distinct URLs
you've served rather than how much traffic you get. vercel#94890 has several
production reports, including two deployments that patched key
accounting in and saw memory go flat.

The idea of the fix is to make the cache's bookkeeping match what an
entry actually keeps alive, so the budget becomes a real memory bound.
That takes three things:

1. Count the key string, not just the value.
2. Count the fixed cost an entry has regardless of string lengths — the
per-entry bookkeeping objects, measured at ~120 bytes. Without this, a
flood of *short* unique URLs stays "cheap" on paper while the
bookkeeping itself grows unbounded.
3. Copy strings before caching them. When V8 takes a substring of a long
string (which is how the pathname is extracted from the request URL), it
doesn't copy the characters — it creates a small object that points into
the original string, and the original can't be garbage-collected while
the substring is alive. So caching a 30-char pathname could actually
hold the entire URL in memory, kilobyte query string and all, and the
bookkeeping only sees the 30 chars. Copying the string before caching
makes it hold only its own characters.

With the bookkeeping honest, the budget is set to 8 MiB, roughly the
real memory the cache could already use for legitimate entries before
this change, so capacity isn't reduced — the previous attempt at this
fix (vercel#94942) stalled on that concern.


## Test Plan

A/B on a production `next start` serving 60k requests with unique long
URLs (the reported traffic shape): canary grows +79 MB and keeps
growing; this branch grows +9 MB and plateaus — the budget working as
intended. The per-entry costs above were measured directly on the cache
with forced GC (they fit `118 + key length` bytes within a few percent,
which is also what predicts the A/B numbers). `lru-cache` unit tests
(26/26) and `pnpm --filter=next types` pass.

---------

Co-authored-by: Marcos Hernanz <96699542+marcoshernanz@users.noreply.github.com>
Co-authored-by: dmchoi77 <dm.choi.dev@gmail.com>
m-kawafuji pushed a commit to m-kawafuji/next.js that referenced this pull request Aug 8, 2026
Fixes vercel#94890

Adopted from vercel#96187 and vercel#94699, with both authors credited on the
commit.

The router server keeps an in-memory cache that maps request URL paths
to what they resolve to: a page, a static file, or nothing.

It's bounded by a size budget, but the size of each entry was computed
from the cached value only. The URL string used as the key was free, and
"resolves to nothing" entries counted as size 1. So a long-lived server
receiving many unique URLs — bot crawls, long slugs, `/order/:id`-style
traffic — could accumulate up to ~1M URL strings while the cache
believed it was within budget.

That looks like a slow memory leak that tracks how many distinct URLs
you've served rather than how much traffic you get. vercel#94890 has several
production reports, including two deployments that patched key
accounting in and saw memory go flat.

The idea of the fix is to make the cache's bookkeeping match what an
entry actually keeps alive, so the budget becomes a real memory bound.
That takes three things:

1. Count the key string, not just the value.
2. Count the fixed cost an entry has regardless of string lengths — the
per-entry bookkeeping objects, measured at ~120 bytes. Without this, a
flood of *short* unique URLs stays "cheap" on paper while the
bookkeeping itself grows unbounded.
3. Copy strings before caching them. When V8 takes a substring of a long
string (which is how the pathname is extracted from the request URL), it
doesn't copy the characters — it creates a small object that points into
the original string, and the original can't be garbage-collected while
the substring is alive. So caching a 30-char pathname could actually
hold the entire URL in memory, kilobyte query string and all, and the
bookkeeping only sees the 30 chars. Copying the string before caching
makes it hold only its own characters.

With the bookkeeping honest, the budget is set to 8 MiB, roughly the
real memory the cache could already use for legitimate entries before
this change, so capacity isn't reduced — the previous attempt at this
fix (vercel#94942) stalled on that concern.


## Test Plan

A/B on a production `next start` serving 60k requests with unique long
URLs (the reported traffic shape): canary grows +79 MB and keeps
growing; this branch grows +9 MB and plateaus — the budget working as
intended. The per-entry costs above were measured directly on the cache
with forced GC (they fit `118 + key length` bytes within a few percent,
which is also what predicts the A/B numbers). `lru-cache` unit tests
(26/26) and `pnpm --filter=next types` pass.

---------

Co-authored-by: Marcos Hernanz <96699542+marcoshernanz@users.noreply.github.com>
Co-authored-by: dmchoi77 <dm.choi.dev@gmail.com>

This branch has not been deployed

No deployments
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.

getItemsLru size accounting omits URL key length, causing excessive heap retention in long-lived servers

1 participant