[RFC] chore: Don't name externals in mergeExternals#2616
Conversation
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:No major changes. 📋 All resultsClick to reveal the results table (355 entries).
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu. |
Resolution Time Benchmark---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.90, 1.87, 4.10, 6.66, 8.00, 11.11, 21.55, 25.33]
line [0.90, 1.78, 4.10, 5.96, 7.23, 11.76, 20.98, 24.46]
line [0.93, 1.76, 4.24, 6.51, 7.50, 11.65, 21.56, 23.71]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.33, 0.74, 0.72, 0.84, 1.15, 1.19, 1.45, 1.52]
line [0.35, 0.48, 0.66, 0.85, 1.11, 1.14, 1.58, 1.57]
line [0.28, 0.58, 0.76, 0.87, 1.18, 1.26, 1.51, 1.55]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.78, 2.12, 4.34, 7.27, 12.81, 26.99, 55.93, 118.22]
line [0.77, 2.06, 3.71, 6.16, 12.08, 24.74, 53.10, 108.88]
line [0.98, 2.12, 3.88, 6.16, 12.17, 25.49, 55.44, 110.19]
|
| it("resolved externals's names stay the same", () => { | ||
| const c1 = (() => tgpu.const(d.vec2u, d.vec2u(1)))(); // unnamed | ||
| tgpu.resolve([tgpu.fn([])`() { let a = myConst; }`.$uses({ myConst: c1 })]); | ||
| tgpu.resolve([tgpu.fn([])`() { let a = otherName; }`.$uses({ otherName: c1 })]); | ||
|
|
||
| expect(getName(c1)).toMatchInlineSnapshot(`"myConst"`); | ||
| }); |
There was a problem hiding this comment.
This makes me wonder if we should do anything at all, though I don't think it's that much of an issue
There was a problem hiding this comment.
I think it's fine, I think it's unusual for a thing to be references by other names in different WGSL templates, and even if it is, it's still a valid name for it.
There was a problem hiding this comment.
This was a very useful case for ambient naming (through external keys), as time is the result of calling useUniform, a helper API that's not instrumented by unplugin-typegpu to be auto-named.
What we could do instead, is add a separate mechanism of ambient naming to 'use gpu' shader functions. When an external is retrieved using getById, and it is namable, we can name it. Same whenever we access a prop, we can name the value using the key if its namable. Wdyt?
There was a problem hiding this comment.
Great idea! I thought we could just add more cases to plugin autonaming, but this seems to do the job
There was a problem hiding this comment.
ℹ️ Minor suggestion inline — otherwise looks solid.
Reviewed changes — removes the auto-naming logic from mergeExternals and shifts responsibility to replaceExternalsInWgsl for raw WGSL and the plugin for TGSL, with a follow-up fix for the guarded compute pipeline.
- Remove
setNamefrommergeExternals— the function no longer names unnamed externals by map key, avoiding depth-dependent naming bugs and the perf cost ofisResolvablein that path. - Add
setNameinreplaceExternalsInWgsl— for raw WGSL functions, unnamed resolvable externals are now named from the last component of their external key (e.g.ext.n2→n2) before resolution. - Explicit
$nameincreateGuardedComputePipeline— thewrappedCallbackwas previously named bymergeExternals; added an explicit$name('wrappedCallback')call. - Snapshot updates — doc example tests now show
item(themakeUniqueIdentifierdefault) instead oftimefor unnamed externals.
Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:
packages/typegpu/src/core/resolve/externals.ts:18(RIGHT) — line 18 (RIGHT) is not inside a diff hunk
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — adds TGSL-side externals naming in getById and accessProp, completing externals naming coverage that was missing from the prior review (which only covered raw WGSL in replaceExternalsInWgsl).
- Name externals in
getById— whenItemStateStackImpl.getSnippetByIdfetches a namelessTgpuNamableexternal fromlayer.externalMap[id], it now names it with that ID (e.g.,myConst). - Name externals in
accessProp— when accessing a property on a comptime-known target that yields a namelessTgpuNamablevalue, it is named with the property name. - New tests for naming coverage — added
"names used externals"and"names used nested externals"totgslFn.test.ts, plus"names resolved externals"/"resolved externals's names stay the same"torawFn.test.ts. - Removed doc snapshot churn — the
time→itemsnapshot updates in doc example tests were reverted, since unnamed externals now carry proper names.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
iwoplaza
left a comment
There was a problem hiding this comment.
I like these changes! 💜

Currently, whether an unnamed item is autonamed in
mergeExternalsdepends on its depth in plugin-generated externals:As seen in #2593, an actual deep pass for proper autonaming is not only difficult, but also hits the performance due to how long
isResolvabletakes.I think removing this may be a good step in order to make our externals both correct and performant.