Repository navigation
feat: Make schemasEqualStructurally & schemasEqualNominally callable at comptime - #3221
Conversation
|
pkg.pr.new packages benchmark commit |
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.53, 1.07, 2.25, 3.52, 4.13, 6.76, 12.53, 13.74]
line [0.49, 1.03, 2.26, 3.35, 3.54, 6.50, 13.20, 13.67]
line [0.50, 1.04, 2.17, 3.41, 4.06, 7.01, 14.08, 13.48]
---
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.19, 0.31, 0.42, 0.48, 0.62, 0.69, 0.78, 0.88]
line [0.18, 0.31, 0.38, 0.46, 0.60, 0.62, 0.72, 0.81]
line [0.17, 0.28, 0.39, 0.41, 0.59, 0.64, 0.77, 0.85]
---
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.47, 1.22, 2.26, 4.04, 6.83, 14.34, 31.35, 62.54]
line [0.50, 1.16, 2.01, 4.01, 7.14, 15.35, 30.30, 60.13]
line [0.60, 1.43, 2.19, 3.82, 7.13, 14.04, 31.09, 63.76]
|
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased (max 791.59%) | ❔ Unknown |
|---|---|---|---|
| 0 | 347 | 6 | 2 |
import * as ... in PR vs import * as ... in target (did bundle size increase?):
| Test | tsdown |
|---|---|
| d_deepEqual.ts | 22.79 kB ( |
| d_schemasEqualNominally.ts | 22.79 kB |
| d_schemasEqualStructurally.ts | 22.79 kB |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
a12f19f to
f78b76b
Compare
f78b76b to
315facb
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The focused wrappers preserve comparison logic, and regression tests cover shader resolution with no identified blocking issues.
No open issues 🎉
What changed in this PR
Enables schema equality checks during shader generation while preserving JavaScript behavior.
Changes:
- Wraps both equality helpers in named
comptimefunctions. - Adds shader-resolution tests demonstrating true and false branch pruning.
| File | Description |
|---|---|
| packages/typegpu/tests/data/schemasEqualStructurally.test.ts | Tests structural equality and true-branch pruning. |
| packages/typegpu/tests/data/schemasEqualNominally.test.ts | Tests nominal inequality and false-branch pruning. |
| packages/typegpu/src/data/schemasEqual.ts | Makes both helpers callable at compile time. |
Review effort: Balanced
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
schemasEqualStructurally/schemasEqualNominallybecome comptime wrappers — both public exports inpackages/typegpu/src/data/schemasEqual.tsare nowcomptime((a, b): boolean => schemasEqual(a, b, <structural>)).$name(...); the private recursiveschemasEqualis unchanged.- Added resolution tests — each public test file gains
it('can be called at comptime in a shader function'), asserting branch pruning (return 1for the structural case,return 0for the nominal case).
The wrapper preserves JS behavior: comptime's returned implementation forwards plain calls to the inner function, so existing callers (core/slot/accessor.ts, typegpu-react/src/core/helper-hooks.ts) are unaffected. The pattern matches existing usages in data/matrix.ts, data/array.ts, and data/disarray.ts. I verified both new test files pass, npx tsc --noEmit in packages/typegpu is clean, and a scratch probe confirmed comptime evaluation preserves object identity for schemasEqualNominally(A, A) (→ true) and recurses correctly into nested structs — cases the added tests don't cover but which work as intended.
( ◦°^°◦) 🏴☠️
Arr! I read the whole diff end to end, ran both new test files plus a scratch probe for same-identity and nested-schema comptime equality, and typechecked the package — no leaks in the hull. Ship it!
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
315facb to
0365f5b
Compare
5e17ca7 to
2be759d
Compare
2be759d to
fed373c
Compare
fed373c to
8231b2f
Compare

Stacked on #3209.
Wraps
schemasEqualStructurallyandschemasEqualNominallyintgpu.comptime, so they can be called inside'use gpu'functions to branch on schema equality during shader generation (unreached branches are pruned). They behave the same as before when called from JS.Added a resolution test to both test files.