Skip to content

Commit 4ae408f

Browse files
ryansolidclaude
andauthored
build(signals): pin mangled _-prop names in a checked-in map (#4503)
* build(signals): pin mangled _-prop names in a checked-in map terser hands out short property names in first-seen order, so one added or renamed field reshuffled names across the prod/observe trees and moved brotli on unrelated size scenarios. scripts/mangle-props.json seeds the shared nameCache per tree; existing fields keep their names, new fields take unused names, removed fields drop out. Generated from next @ 643a7a7: dist is byte-identical. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * build: restore the pinned mangle map on a turbo cache hit A cache hit restored dist but not a map the build wrote back, so the next build re-derived names the cached dist did not use. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 --------- Co-authored-by: Claude <[email protected]>
1 parent 64fedc7 commit 4ae408f

3 files changed

Lines changed: 354 additions & 7 deletions

File tree

Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
{
2+
"prod": {
3+
"_acted": "nt",
4+
"_armLane": "B",
5+
"_armed": "h",
6+
"_blocked": "fe",
7+
"_born": "ro",
8+
"_boundRunEffect": "W",
9+
"_byIndex": "ut",
10+
"_changed": "V",
11+
"_childCount": "be",
12+
"_cleanup": "ze",
13+
"_collapse": "At",
14+
"_collapsed": "ee",
15+
"_config": "l",
16+
"_confirmed": "tn",
17+
"_context": "A",
18+
"_count": "dt",
19+
"_dep": "S",
20+
"_depGen": "de",
21+
"_deps": "C",
22+
"_depsTail": "_",
23+
"_disposal": "ke",
24+
"_dispose": "Ce",
25+
"_done": "Lt",
26+
"_echoes": "sn",
27+
"_effectFn": "qe",
28+
"_equals": "ye",
29+
"_error": "U",
30+
"_errorFn": "Je",
31+
"_evaluate": "_t",
32+
"_evaluating": "gt",
33+
"_extraConfig": "xe",
34+
"_fallback": "L",
35+
"_fb": "re",
36+
"_firstChild": "pe",
37+
"_flags": "R",
38+
"_flightTeardown": "Se",
39+
"_flushed": "je",
40+
"_flushedAt": "Be",
41+
"_fn": "X",
42+
"_from": "Ot",
43+
"_gated": "$",
44+
"_gen": "Ne",
45+
"_heap": "et",
46+
"_height": "he",
47+
"_held": "un",
48+
"_host": "O",
49+
"_inFlight": "Ee",
50+
"_indexes": "lt",
51+
"_inherited": "no",
52+
"_initialized": "D",
53+
"_into": "eo",
54+
"_isMinReady": "Rt",
55+
"_isReady": "St",
56+
"_items": "ot",
57+
"_key": "Xe",
58+
"_lagging": "er",
59+
"_lane": "P",
60+
"_laneRebase": "In",
61+
"_len": "it",
62+
"_links": "nn",
63+
"_list": "st",
64+
"_loading": "Ie",
65+
"_map": "ft",
66+
"_mappings": "ht",
67+
"_mark": "N",
68+
"_marked": "p",
69+
"_marks": "I",
70+
"_max": "Et",
71+
"_min": "Fe",
72+
"_minReady": "vt",
73+
"_modified": "Ae",
74+
"_nextDep": "G",
75+
"_nextHeap": "ve",
76+
"_nextSibling": "Ge",
77+
"_nextSub": "t",
78+
"_noSnapshot": "ae",
79+
"_nodes": "ln",
80+
"_notifiedAt": "we",
81+
"_offset": "wt",
82+
"_open": "tt",
83+
"_order": "yt",
84+
"_output": "j",
85+
"_owned": "Mt",
86+
"_owner": "H",
87+
"_parentComputed": "Ke",
88+
"_parked": "He",
89+
"_pendingDisposal": "Le",
90+
"_pendingFirstChild": "me",
91+
"_pendingSources": "se",
92+
"_pendingValue": "ue",
93+
"_prevHeap": "We",
94+
"_prevSibling": "Me",
95+
"_prevSub": "en",
96+
"_prevValue": "ge",
97+
"_q": "ce",
98+
"_queues": "rn",
99+
"_readers": "F",
100+
"_ready": "Ct",
101+
"_reask": "Ve",
102+
"_register": "te",
103+
"_reruns": "fn",
104+
"_reveal": "v",
105+
"_root": "Qe",
106+
"_rows": "ct",
107+
"_run": "Z",
108+
"_runEffect": "q",
109+
"_running": "Y",
110+
"_runs": "M",
111+
"_scope": "oo",
112+
"_served": "$e",
113+
"_show": "ne",
114+
"_shown": "Ue",
115+
"_shownError": "Te",
116+
"_slotCovered": "an",
117+
"_slotFlight": "k",
118+
"_slotTake": "Nn",
119+
"_slots": "kt",
120+
"_snapshotScope": "Oe",
121+
"_snapshotValue": "De",
122+
"_statusFlags": "m",
123+
"_storeNode": "so",
124+
"_storeWrappable": "fo",
125+
"_sub": "u",
126+
"_subs": "o",
127+
"_subsTail": "Ze",
128+
"_time": "ie",
129+
"_transaction": "Re",
130+
"_tree": "K",
131+
"_truth": "En",
132+
"_type": "i",
133+
"_unobserved": "Ye",
134+
"_unregister": "oe",
135+
"_update": "_e",
136+
"_value": "le",
137+
"_verdict": "Pe",
138+
"_verdictLane": "J",
139+
"_witness": "io",
140+
"_witnessMark": "rt",
141+
"_x": "T"
142+
},
143+
"observe": {
144+
"_acted": "nt",
145+
"_armLane": "B",
146+
"_armed": "h",
147+
"_blocked": "fe",
148+
"_born": "ro",
149+
"_boundRunEffect": "W",
150+
"_byIndex": "qt",
151+
"_changed": "P",
152+
"_childCount": "At",
153+
"_cleanup": "Vt",
154+
"_collapse": "ts",
155+
"_collapsed": "ee",
156+
"_config": "l",
157+
"_confirmed": "tn",
158+
"_context": "A",
159+
"_count": "Bt",
160+
"_dep": "S",
161+
"_depGen": "de",
162+
"_deps": "C",
163+
"_depsTail": "_",
164+
"_devChange": "ge",
165+
"_devCopyFrom": "qe",
166+
"_devCopyRuns": "Ue",
167+
"_devExcluded": "he",
168+
"_devHotWarned": "$e",
169+
"_devRunCauses": "pe",
170+
"_devRunCount": "De",
171+
"_devRunInteraction": "Me",
172+
"_devRunSeq": "me",
173+
"_devSeenSeq": "we",
174+
"_devSoleWriter": "Pe",
175+
"_devTimeWarned": "Oe",
176+
"_devTimeWinMs": "_e",
177+
"_devTimeWinStart": "be",
178+
"_devUnstableRuns": "He",
179+
"_devUnstableWarned": "We",
180+
"_devWasteRuns": "Ae",
181+
"_devWasteWarned": "Ce",
182+
"_devWasteWinStart": "Fe",
183+
"_devWasted": "Re",
184+
"_devWastedMs": "Le",
185+
"_devWaterfallWarnedAt": "Ke",
186+
"_devWideWarnedAt": "ve",
187+
"_devWinCount": "ye",
188+
"_devWinStart": "ke",
189+
"_devWindows": "Ve",
190+
"_disposal": "_t",
191+
"_dispose": "et",
192+
"_done": "ns",
193+
"_echoes": "sn",
194+
"_effectFn": "Ge",
195+
"_equals": "je",
196+
"_error": "U",
197+
"_errorFn": "kt",
198+
"_evaluate": "Xt",
199+
"_evaluating": "rs",
200+
"_extraConfig": "ct",
201+
"_fallback": "L",
202+
"_fb": "re",
203+
"_firstChild": "ze",
204+
"_flags": "R",
205+
"_flightTeardown": "Se",
206+
"_flushed": "Ft",
207+
"_flushedAt": "ht",
208+
"_fn": "X",
209+
"_from": "Jt",
210+
"_gated": "$",
211+
"_gen": "Ne",
212+
"_heap": "jt",
213+
"_height": "lt",
214+
"_held": "ln",
215+
"_host": "O",
216+
"_id": "Be",
217+
"_inFlight": "Ee",
218+
"_indexes": "xt",
219+
"_inherited": "no",
220+
"_initialized": "D",
221+
"_into": "eo",
222+
"_isMinReady": "Qt",
223+
"_isReady": "Lt",
224+
"_items": "Wt",
225+
"_key": "gt",
226+
"_lagging": "er",
227+
"_lane": "V",
228+
"_laneGuesses": "xe",
229+
"_laneRebase": "Nn",
230+
"_len": "wt",
231+
"_links": "nn",
232+
"_list": "Mt",
233+
"_loading": "Ie",
234+
"_map": "vt",
235+
"_mappings": "Kt",
236+
"_mark": "N",
237+
"_marked": "p",
238+
"_marks": "I",
239+
"_max": "yt",
240+
"_min": "Et",
241+
"_minReady": "ss",
242+
"_modified": "Qe",
243+
"_nextDep": "G",
244+
"_nextHeap": "Rt",
245+
"_nextSibling": "Xe",
246+
"_nextSub": "t",
247+
"_noSnapshot": "ae",
248+
"_nodes": "Ye",
249+
"_notifiedAt": "Dt",
250+
"_offset": "zt",
251+
"_open": "tt",
252+
"_order": "Zt",
253+
"_output": "j",
254+
"_owned": "ls",
255+
"_owner": "H",
256+
"_parentComputed": "Pt",
257+
"_parked": "rt",
258+
"_pendingDisposal": "Tt",
259+
"_pendingFirstChild": "ft",
260+
"_pendingSources": "se",
261+
"_pendingValue": "ue",
262+
"_plumbing": "St",
263+
"_prevHeap": "Ct",
264+
"_prevSibling": "dt",
265+
"_prevSub": "en",
266+
"_prevValue": "It",
267+
"_q": "ce",
268+
"_queues": "rn",
269+
"_readers": "F",
270+
"_ready": "Yt",
271+
"_reask": "ut",
272+
"_register": "te",
273+
"_reruns": "En",
274+
"_reveal": "v",
275+
"_root": "Ht",
276+
"_rows": "$t",
277+
"_run": "Z",
278+
"_runEffect": "q",
279+
"_running": "Y",
280+
"_runs": "M",
281+
"_scope": "oo",
282+
"_served": "Ut",
283+
"_show": "ne",
284+
"_shown": "Nt",
285+
"_shownError": "Te",
286+
"_slotCovered": "an",
287+
"_slotFlight": "k",
288+
"_slotTake": "fn",
289+
"_slots": "es",
290+
"_snapshotScope": "ot",
291+
"_snapshotValue": "st",
292+
"_statusFlags": "m",
293+
"_storeNode": "so",
294+
"_storeWrappable": "fo",
295+
"_sub": "u",
296+
"_subs": "o",
297+
"_subsTail": "Ot",
298+
"_time": "ie",
299+
"_transaction": "Je",
300+
"_tree": "K",
301+
"_truth": "un",
302+
"_type": "i",
303+
"_unobserved": "Gt",
304+
"_unregister": "oe",
305+
"_update": "Ze",
306+
"_value": "le",
307+
"_verdict": "it",
308+
"_verdictLane": "J",
309+
"_witness": "io",
310+
"_witnessMark": "bt",
311+
"_x": "T"
312+
}
313+
}

‎packages/signals/scripts/mangle-props.mjs‎

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,26 @@
1010
* Each argument is one consistency domain with its own nameCache: a directory
1111
* tree (the prod and observe trees) or a single file.
1212
*
13+
* Names are pinned. terser hands out short names in first-seen order, so one
14+
* added or renamed field shifts every name after it and moves brotli on
15+
* scenarios the change never touched. `mangle-props.json` (beside this
16+
* script) holds each domain's field -> name map and seeds the nameCache:
17+
* fields already in it keep their names, a new field takes the next short
18+
* name the map does not hold, and a field gone from the source drops out (its
19+
* name is free for the next new field). The build writes the map back when it
20+
* changes; commit it with the change, like a lockfile. Delete a domain's entry
21+
* (or the file) to re-pack every name from scratch, in a PR of its own.
22+
*
1323
* Usage: node scripts/mangle-props.mjs <dir|file> [...]
1424
*/
15-
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
16-
import { join } from "node:path";
25+
import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
26+
import { basename, join } from "node:path";
1727
import { minify } from "terser";
1828

29+
const MAP = new URL("./mangle-props.json", import.meta.url);
30+
const pins = existsSync(MAP) ? JSON.parse(readFileSync(MAP, "utf8")) : {};
31+
const before = JSON.stringify(pins);
32+
1933
function walk(dir) {
2034
if (statSync(dir).isFile()) return [dir];
2135
const files = [];
@@ -30,9 +44,17 @@ function walk(dir) {
3044
}
3145

3246
for (const dir of process.argv.slice(2)) {
33-
const nameCache = {};
34-
for (const file of walk(dir)) {
35-
const code = readFileSync(file, "utf8");
47+
const key = basename(dir);
48+
const files = walk(dir).map(file => [file, readFileSync(file, "utf8")]);
49+
// Every `_` token in the unmangled tree: a superset of the fields terser
50+
// will mangle, so a pin is dropped only when its field is truly gone.
51+
const tokens = new Set(files.flatMap(([, code]) => code.match(/(?<![\w$])_[\w$]+/g) ?? []));
52+
const props = {};
53+
for (const [prop, name] of Object.entries(pins[key] ?? {}))
54+
if (tokens.has(prop)) props["$" + prop] = name;
55+
// terser's nameCache shape: { props: { props: { $field: name } } }.
56+
const nameCache = { props: { props } };
57+
for (const [file, code] of files) {
3658
const result = await minify(code, {
3759
compress: false,
3860
nameCache,
@@ -63,5 +85,15 @@ for (const dir of process.argv.slice(2)) {
6385
});
6486
writeFileSync(file, result.code);
6587
}
66-
console.log(`mangled _-props across ${walk(dir).length} files in ${dir}`);
88+
pins[key] = Object.fromEntries(
89+
Object.entries(nameCache.props.props)
90+
.map(([prop, name]) => [prop.slice(1), name])
91+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
92+
);
93+
console.log(`mangled _-props across ${files.length} files in ${dir}`);
94+
}
95+
96+
if (JSON.stringify(pins) !== before) {
97+
writeFileSync(MAP, JSON.stringify(pins, null, 2) + "\n");
98+
console.log(`updated ${MAP.pathname} - commit it with this change`);
6799
}

‎turbo.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"outputLogs": "new-only"
88
},
99
"@solidjs/signals#build": {
10-
"outputs": ["dist/**"]
10+
// The pinned mangled-prop map is written back by the build when a field
11+
// is added or removed (scripts/mangle-props.mjs).
12+
"outputs": ["dist/**", "scripts/mangle-props.json"]
1113
},
1214
"@solidjs/signals#types": {
1315
"outputs": ["dist/types/**"]

0 commit comments

Comments
 (0)