fix: Remove 'use gpu' after transformation#2706
Conversation
|
pkg.pr.new packages benchmark commit |
Bundle size comparison (
|
| 🟢 Decreased (max -6.74%) | ➖ Unchanged | 🔴 Increased | ❔ Unknown |
|---|---|---|---|
| 1 | 320 | 0 | 0 |
import * as ... in PR vs import * as ... in target (did bundle size increase?):
| Test | tsdown |
|---|---|
| STATIC_useGpuFunction.ts | 263 B ( |
import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):
| Test | tsdown |
|---|---|
| tgpu_init.ts | 256.45 kB ( |
| tgpu_initFromDevice.ts | 255.93 kB ( |
| tgpu_resolve.ts | 187.16 kB ( |
| tgpu_resolveWithContext.ts | 187.10 kB ( |
| tgpu_bindGroupLayout.ts | 69.01 kB ( |
| tgpu_mutableAccessor.ts | 65.98 kB ( |
| tgpu_accessor.ts | 65.97 kB ( |
| tgpu_privateVar.ts | 65.30 kB ( |
| tgpu_workgroupVar.ts | 65.30 kB ( |
| tgpu_const.ts | 64.53 kB ( |
| tgpu_fn.ts | 37.97 kB ( |
| tgpu_fragmentFn.ts | 37.91 kB ( |
| tgpu_vertexFn.ts | 37.72 kB ( |
| tgpu_computeFn.ts | 37.43 kB ( |
| tgpu_vertexLayout.ts | 26.61 kB ( |
| tgpu_comptime.ts | 14.41 kB ( |
| tgpu_unroll.ts | 2.60 kB ( |
| tgpu_slot.ts | 1.57 kB ( |
| tgpu_lazy.ts | 1.22 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.80, 1.65, 3.31, 5.29, 6.68, 10.82, 18.68, 19.70]
line [0.87, 1.69, 3.85, 5.64, 6.42, 10.23, 19.79, 21.99]
line [0.85, 1.64, 3.61, 5.73, 7.27, 10.58, 18.91, 19.57]
---
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.27, 0.50, 0.60, 0.70, 0.98, 0.96, 1.27, 1.37]
line [0.29, 0.49, 0.71, 0.76, 1.04, 1.09, 1.27, 1.42]
line [0.28, 0.50, 0.61, 0.75, 1.00, 1.06, 1.27, 1.41]
---
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.80, 1.90, 4.33, 6.16, 11.75, 24.06, 48.56, 100.40]
line [0.87, 1.88, 4.03, 5.50, 10.91, 23.79, 48.61, 99.19]
line [0.84, 1.88, 3.80, 5.72, 11.05, 23.25, 49.95, 100.05]
|
|
@pullfrog review |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — This PR removes the custom "use gpu" directive from functions after TypeGPU transforms them, replacing the previous alreadyTransformed WeakSet guard with directive deletion to prevent re-transformation.
- Remove
"use gpu"after transformation in both the Babel and unplugin/rollup plugin paths by adding aremoveUseGpuDirectivemethod toTransformMethods. - Drop the
alreadyTransformedstate fromPluginState; since the directive is stripped, a second pass no longer recognizes the function as a GPU target. - Add test coverage for directive removal, coexistence with other directives like
'worklet', and double transformation round-trips for both backends. - Update inline snapshots across
auto-naming,typescript-syntax, andautonametests to reflect the absence of the leftover directive.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — this PR removes the 'use gpu' directive from transformed functions so a second transform pass doesn't re-process them, replacing the previous alreadyTransformed WeakSet guard.
- Updated the Babel transform (
packages/unplugin-typegpu/src/babel.ts) by addingremoveUseGpuDirectiveand dropping thealreadyTransformedcheck inassignMetadata. - Updated the unplugin/Rollup transform (
packages/unplugin-typegpu/src/core/factory.ts) with a MagicString-based directive removal implementation. - Updated shared core state (
packages/unplugin-typegpu/src/core/common.ts) to exposeremoveUseGpuDirectiveand remove the now-unusedalreadyTransformedstate. - Refreshed inline snapshots in auto-naming, TypeScript-syntax, and the internal TypeGPU autoname test.
- Added regression tests covering directive removal (with siblings preserved) and double transformation for both Babel and Rollup.
Kimi K2 (free via Pullfrog for OSS) | 𝕏

No description provided.