Repository navigation
feat: Expand property access in externals - #2425
Conversation
|
pkg.pr.new packages benchmark commit |
Bundle size comparison (
|
| 🟢 Decreased (max -8.75%) | ➖ Unchanged | 🔴 Increased (max 0.00%) | ❔ Unknown |
|---|---|---|---|
| 3 | 297 | 21 | 0 |
import * as ... in PR vs import * as ... in target (did bundle size increase?):
| Test | tsdown |
|---|---|
| STATIC_useGpuFunction.ts | 240 B ( |
import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):
| Test | tsdown |
|---|---|
| tgpu_init.ts | 255.88 kB ( |
| tgpu_initFromDevice.ts | 255.37 kB ( |
| tgpu_resolve.ts | 161.34 kB ( |
| tgpu_resolveWithContext.ts | 161.28 kB ( |
| tgpu_bindGroupLayout.ts | 68.92 kB ( |
| tgpu_mutableAccessor.ts | 65.91 kB ( |
| tgpu_accessor.ts | 65.90 kB ( |
| tgpu_privateVar.ts | 65.27 kB ( |
| tgpu_workgroupVar.ts | 65.27 kB ( |
| tgpu_const.ts | 64.52 kB ( |
| tgpu_fn.ts | 37.98 kB ( |
| tgpu_fragmentFn.ts | 37.88 kB ( |
| tgpu_vertexFn.ts | 37.70 kB ( |
| tgpu_computeFn.ts | 37.40 kB ( |
| tgpu_vertexLayout.ts | 26.63 kB ( |
| tgpu_comptime.ts | 14.43 kB ( |
| tgpu_unroll.ts | 2.60 kB ( |
| tgpu_slot.ts | 1.54 kB ( |
| tgpu_lazy.ts | 1.19 kB ( |
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.65, 1.38, 2.95, 4.25, 4.69, 7.98, 14.93, 15.28]
line [0.70, 1.32, 2.84, 4.54, 5.29, 7.63, 15.23, 17.43]
line [0.72, 1.44, 3.05, 4.52, 5.16, 8.70, 15.91, 16.40]
---
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.20, 0.40, 0.46, 0.58, 0.79, 0.85, 0.98, 1.11]
line [0.25, 0.41, 0.51, 0.62, 0.86, 0.89, 1.03, 1.14]
line [0.25, 0.44, 0.49, 0.63, 0.87, 0.86, 1.07, 1.21]
---
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.65, 1.70, 2.70, 4.81, 8.41, 18.85, 37.24, 77.58]
line [0.69, 1.56, 2.96, 4.82, 9.09, 18.31, 38.92, 78.70]
line [0.66, 1.58, 2.83, 5.77, 9.57, 18.99, 38.69, 79.44]
|
e29acd4 to
d6e4f7e
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — moved the visited-node optimization set from a module-level WeakMap<Context, Set<JsNode>> into the per-transpilation Context.
packages/tinyest-for-wgsl/src/types.ts— addedvisitedNodes: Set<JsNode>toContext.packages/tinyest-for-wgsl/src/parsers.ts— initializesvisitedNodesin bothtranspileFnandtranspileNodecontexts.packages/tinyest-for-wgsl/src/externals.ts— removed the module-levelWeakMapand readsctx.visitedNodesdirectly.
Ran pnpm vitest run --project=!browser packages/tinyest-for-wgsl/tests/parsers.test.ts and pnpm --filter tinyest-for-wgsl test:types; both pass.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
Co-authored-by: Szymon Szulc <103948576+cieplypolar@users.noreply.github.com>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — switched auto-naming for flattened external chains from the leaf segment to the full chain with underscores, and applied a few doc wording fixes since the last Pullfrog review.
- Full-chain underscore auto-naming in
packages/typegpu/src/core/resolve/externals.tsandpackages/typegpu/src/resolutionCtx.ts. A flattened chain likeEXT.myConstnow primes the WGSL identifier asEXT_myConst, so distinct chains with the same leaf no longer collide unless they normalize to the same string. - Snapshot updates in
packages/typegpu/tests/rawFn.test.tsandpackages/typegpu/tests/tgslFn.test.tsreflect the new identifiers. - Doc wording fixes in
apps/typegpu-docs/src/content/docs/advanced/explaining-the-magic.mdxcorrected typos and updated the operator-overloading reference.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
reczkok
left a comment
There was a problem hiding this comment.
Looks good, great docs! Left some nits
|
|
||
| function externalsToString(externals: Externals): string { | ||
| const entries = Array.from(externals, (key) => `"${key}": () => ${key}`); | ||
| return `{ ${entries.join(', ')} }`; |
There was a problem hiding this comment.
nit: Could we kill the spaces in empty cases?
There was a problem hiding this comment.
The rest of metadata uses no spaces (ast: {"params":[],"body":[0,[]]},), so I just killed them altogether for consistency
| * tryFindExternalChain(ctx, node`local.p.q`); // undefined | ||
| * tryFindExternalChain(ctx, node`ext.$.q`); // undefined | ||
| */ | ||
| export function tryFindExternalChain(ctx: Context, node: JsNode): string | undefined { |
There was a problem hiding this comment.
For most nodes this will go all the way though right? Couldn't we invert the logic so unless one of the nodes (identifier, this, member) we don't even add it to the Set?
There was a problem hiding this comment.
The function only traverses down when it actually may be an external chain. See some of my debug below. Do you just want to optimize how many nodes we keep in this set?
Calling tryFindExternalChain...
Visiting node type: BlockStatement
No external chain found.
Calling tryFindExternalChain...
Visiting node type: VariableDeclaration
No external chain found.
Calling tryFindExternalChain...
Visiting node type: MemberExpression
Visiting node type: Identifier
Found external chain: ext.value
Calling tryFindExternalChain...
Visiting node type: VariableDeclaration
No external chain found.
Calling tryFindExternalChain...
Visiting node type: MemberExpression
Visiting node type: MemberExpression
Visiting node type: Identifier
Found external chain: ext.config.multiplier
Calling tryFindExternalChain...
Visiting node type: VariableDeclaration
No external chain found.
Calling tryFindExternalChain...
Visiting node type: MemberExpression
Visiting node type: MemberExpression
Visiting node type: Identifier
Found external chain: ext.config.zero
Calling tryFindExternalChain...
Visiting node type: VariableDeclaration
No external chain found.
Calling tryFindExternalChain...
Visiting node type: MemberExpression
Visiting node type: MemberExpression
Visiting node type: Identifier
Found external chain: ext.config.multiplier
Calling tryFindExternalChain...
Visiting node type: BlockStatement
No external chain found.
Calling tryFindExternalChain...
Visiting node type: VariableDeclaration
No external chain found.
Calling tryFindExternalChain...
Visiting node type: MemberExpression
Visiting node type: Identifier
Found external chain: ext.value
There was a problem hiding this comment.
Actually, we only travel down member expressions, so it would suffice to just keep those (at least until we update externals again)
Co-authored-by: Konrad Reczko <66403540+reczkok@users.noreply.github.com>
…ic.mdx Co-authored-by: Konrad Reczko <66403540+reczkok@users.noreply.github.com>
…access-in-externals
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — two fixes from main landed on the branch: the raw-WGSL external resolver was rewritten to walk nested externals via bounded identifier chains, and tinyest-for-wgsl now scopes for/for ... of loop variables so they no longer shadow external names after the loop.
- Rewrote
replaceExternalsInWgslinpackages/typegpu/src/core/resolve/externals.tsto scan bounded identifier/property chains (anyIdent/boundedPropChain) and walk nestedExternalMapvalues until it reaches a resolvable. Externals are now resolved in lexical order and unused externals are no longer auto-resolved. - Scoped
for/for ... ofheads inpackages/tinyest-for-wgsl/src/parsers.tsby pushing/popping a scope around init/test/update/body, preventing a loop-local identifier from being treated as an external in code that follows the loop. - Added regression tests for raw-WGSL external chains, for-loop variable shadowing, and updated
declare.test.tsplus console-log snapshots to match the new resolution order. - Synchronized
mainand updated the PR-package publishing workflow (pkg-pr.yml) to only publish packages that changed sincerelease.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
|
@aleksanderkatan we need to add a note that typescript types are completely ignored in our magic |
There was a problem hiding this comment.
ℹ️ No critical issues — minor suggestions inline.
Reviewed changes — merged main fixes for removing the 'use gpu' directive after transformation and tightening the test helper; updated snapshots and one conversion test.
- Remove
'use gpu'after transformation inpackages/unplugin-typegpu/src/babel.tsandpackages/unplugin-typegpu/src/core/factory.ts: the plugin now removes the prologue directive instead of leaving it as a stray string literal, and drops thealreadyTransformedguard because a second pass no longer sees the directive. - Refresh snapshots in
use-gpu-directive.test.ts,auto-naming.test.ts, andtypescript-syntax.test.tsto reflect the directive removal and the current v2 metadata shape. - Tighten
expectDataTypeOf/expectSnippetOfinpackages/typegpu/tests/utils/parseResolved.tsto accept only() => unknown, and updateconversion.test.tsto invoke the helper through a'use gpu'wrapper.
Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:
packages/unplugin-typegpu/src/babel.ts:158(RIGHT) — line 158 (RIGHT) is not inside a diff hunk
Kimi K2 (free via Pullfrog for OSS) | 𝕏
The observation, as a non-anchored note: In All relevant tests pass, so this is a minor edge-case polish rather than a blocker.
|

Closes #2504
Closes #2019
See the new doc for description on how now externals work.
The cut-off at '.$' actually changes some behavior: with .$ in externals, number slots resolve to abstract numbers instead of concrete.