dx: More robust snippet testing#2716
Conversation
|
@pullfrog review |
|
pkg.pr.new packages benchmark commit |
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased | ❔ Unknown |
|---|---|---|---|
| 0 | 321 | 0 | 0 |
import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):
| Test | tsdown |
|---|---|
| tgpu_init.ts | 256.14 kB ( |
| tgpu_initFromDevice.ts | 255.63 kB ( |
| tgpu_resolve.ts | 161.62 kB ( |
| tgpu_resolveWithContext.ts | 161.55 kB ( |
| tgpu_bindGroupLayout.ts | 68.88 kB ( |
| tgpu_mutableAccessor.ts | 65.83 kB ( |
| tgpu_accessor.ts | 65.81 kB ( |
| tgpu_privateVar.ts | 65.23 kB ( |
| tgpu_workgroupVar.ts | 65.23 kB ( |
| tgpu_const.ts | 64.48 kB ( |
| tgpu_fn.ts | 38.07 kB ( |
| tgpu_fragmentFn.ts | 37.97 kB ( |
| tgpu_vertexFn.ts | 37.78 kB ( |
| tgpu_computeFn.ts | 37.49 kB ( |
| tgpu_vertexLayout.ts | 26.62 kB ( |
| tgpu_comptime.ts | 14.42 kB ( |
| tgpu_unroll.ts | 2.59 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.90, 1.74, 3.90, 5.17, 6.51, 11.09, 20.62, 21.35]
line [0.85, 1.71, 3.75, 5.46, 6.32, 10.85, 19.57, 21.39]
line [0.88, 1.80, 3.78, 5.45, 6.62, 10.52, 21.39, 22.25]
---
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.29, 0.45, 0.60, 0.73, 0.98, 1.08, 1.27, 1.43]
line [0.31, 0.48, 0.65, 0.77, 1.05, 1.07, 1.31, 1.41]
line [0.32, 0.51, 0.68, 0.85, 1.11, 1.17, 1.34, 1.49]
---
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.74, 2.00, 3.32, 5.81, 10.80, 23.52, 48.10, 96.90]
line [0.81, 1.86, 3.53, 5.62, 10.92, 22.82, 48.50, 99.44]
line [0.78, 1.86, 3.74, 7.06, 11.20, 23.23, 48.54, 101.33]
|
There was a problem hiding this comment.
Important
The new capture.ts file imports tinyest at runtime, but packages/typegpu-testing-utility/package.json does not declare it as a dependency. Running pnpm vitest run --project=!browser packages/typegpu/tests/internal/capturedSnippets.test.ts fails with ERR_MODULE_NOT_FOUND in a clean workspace install (verified locally). Adding tinyest to the testing utility's dependencies resolves the failure.
Reviewed changes — adds a CAPTURE-based snippet extraction utility for more robust TGSL tests, plus the internal exports it needs.
- Add
CapturingGenerator,CAPTURE,captureSnippets, andsimplifyTypeintypegpu-testing-utilityto intercept and collect WGSL snippets during resolution. - Export
dualImplfromtypegpu/~internalso the utility can build a dual-implementation marker function. - Add unit tests in
packages/typegpu/tests/internal/capturedSnippets.test.tscovering regular-resolve no-op behavior, snippet extraction, repeated captures, and inner-to-outer capture ordering.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes since last review — the follow-up commit adds the missing tinyest dependency to packages/typegpu-testing-utility/package.json (and the lockfile) so the new capture.ts module can resolve its runtime import in a clean pnpm workspace.
- Add
tinyestas a runtime dependency oftypegpu-testing-utilityusing theworkspace:*spec.
I verified pnpm vitest run --project=!browser packages/typegpu/tests/internal/capturedSnippets.test.ts now passes and both typegpu-testing-utility and typegpu typecheck cleanly.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — added a CAPTURE dual-impl helper and captureSnippets utility to the testing package, plus internal exports needed to support them.
- Add
CAPTURE/captureSnippets/simplifyTypetotypegpu-testing-utility—CAPTUREis transparent in normal resolves and records its argument's snippet when resolved throughCapturingGenerator. - Expose
dualImplfromtypegpu/~internal— required to declareCAPTUREas aDualFn. - Add
capturedSnippets.test.ts— covers normal resolution transparency, snippet extraction, re-capture, and nested capture ordering.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
it('works with typedExpression - struct', () => {
const Boid = d.struct({
pos: d.vec3f,
});
const fn = tgpu.fn(
[],
Boid,
)(() => {
'use gpu';
return CAPTURE({ pos: d.vec3f() });
});
const captured = captureSnippets(fn);
expect(captured[0]?.value).toMatchInlineSnapshot(`"Boid(vec3f())"`);
});
it('works with typedExpression - numeric', () => {
const fn = tgpu.fn(
[],
d.u32,
)(() => {
'use gpu';
return CAPTURE(d.f32(1.67));
});
const captured = captureSnippets(fn);
expect(captured[0]?.value).toMatchInlineSnapshot(`1.6699999570846558`);
});Could you add these tests?
The second test needs to be fixed.
There was a problem hiding this comment.
So I think we decided that this is intended behavior, and that we want to remove expected type stack, right? I created an issue for that: #2726
There was a problem hiding this comment.
✅ No new issues found.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes since last review — the new commit cleans up the capture.ts imports and adds a regression test verifying struct-literal capture before return-type casting.
- Consolidate
typegpu/~internalimports incapture.ts— pullsdualImplinto the existingtypegpu/~internalimport rather than importing it separately. - Add
captures structs after castingtest — verifies thatCAPTURErecords the originalBoidstruct data type of{ pos: d.vec3f() }before the function return type casts it.
Kimi K2 (free via Pullfrog for OSS) | 𝕏

No description provided.