Skip to content

Commit 829e11a

Browse files
docs-botCopilotEbonsignori
authored
intern languageCode and pageVersion strings in Permalink (#60753)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Evan Bonsignori <evanabonsignori@gmail.com>
1 parent 923e1a7 commit 829e11a

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/frame/lib/permalink.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ page.permalinks is an array of objects that looks like this:
2727
... and so on for each of the content file's supported versions.
2828
]
2929
*/
30+
// String interning pool: deduplicates low-cardinality, highly-repeated values (languageCode, pageVersion)
31+
// across ~975K Permalink instances (~9 languages × ~9 versions × ~65K pages). Because these fields have
32+
// few distinct values (~81 total), the pool stays bounded — do not use intern() for high-cardinality
33+
// fields like relativePath or title, where the pool would grow unbounded and leak memory.
34+
const stringPool = new Map<string, string>()
35+
36+
function intern(s: string): string {
37+
const pooled = stringPool.get(s)
38+
if (pooled !== undefined) return pooled
39+
stringPool.set(s, s)
40+
return s
41+
}
42+
3043
class Permalink {
3144
languageCode: string
3245
pageVersion: string
@@ -36,8 +49,8 @@ class Permalink {
3649
href: string
3750

3851
constructor(languageCode: string, pageVersion: string, relativePath: string, title: string) {
39-
this.languageCode = languageCode
40-
this.pageVersion = pageVersion
52+
this.languageCode = intern(languageCode)
53+
this.pageVersion = intern(pageVersion)
4154
this.relativePath = relativePath
4255
this.title = title
4356

0 commit comments

Comments
 (0)