Repository navigation
fix: Respect custom alignment of nested loose schemas - #3260
cieplypolar wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
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 [1.12, 2.18, 4.68, 6.87, 9.06, 13.71, 28.89, 25.47]
line [1.12, 2.23, 4.63, 7.79, 9.56, 14.60, 28.03, 29.38]
line [1.03, 2.12, 4.66, 7.27, 8.71, 13.99, 26.77, 25.79]
---
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.54, 0.76, 0.93, 1.27, 1.32, 1.64, 1.73]
line [0.37, 0.63, 0.82, 0.97, 1.32, 1.33, 1.66, 1.79]
line [0.33, 0.60, 0.79, 0.92, 1.20, 1.31, 1.54, 1.67]
---
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 [1.03, 2.57, 4.24, 7.81, 13.98, 29.96, 61.34, 123.90]
line [0.96, 2.41, 4.39, 7.77, 14.60, 28.72, 63.10, 129.28]
line [1.01, 2.31, 4.91, 7.84, 16.09, 28.77, 62.63, 125.85]
|
There was a problem hiding this comment.
Caution
This PR does not compile. tsc fails with two TS2322 errors in packages/typegpu/src/data/dataIO.ts, which breaks the typegpu build and every CI job that depends on it (build-and-test on built packages, test:types/test-misc, docs, treeshake, publish). This needs to be fixed before merge.
( ◦°^°◦) 🏴☠️ Avast, me hearties! I read the whole diff, ran the core test suite (2969 tests, all passin'), typechecked the core package, and spied the build barrrking at a type error in the new array writer — she'll never make port with that readonly unknown[] keel.
Reviewed changes
alignmentOfrecursion —unstruct/disarraynow delegate tocustomAlignmentOfinstead of peeking at the first property's raw custom alignment, so custom alignment propagates through nesting.offsetsForPropstrailing padding — usessizeOf(struct)directly, dropping spurious trailing padding forunstruct(no change forWgslStruct, whose size is already rounded).- Fallback reader/writer rewrite —
struct/array/unstruct/disarrayare now placed byoffsetsForPropsoffsets androundUp(sizeOf(elementType), alignmentOf(schema))stride, andalignIOwas removed from thedecorated/loose-decoratedpaths, aligning the fallback with the already-offsets-based compiled writer. getPatchInstructionsstride — derives disarray/array element stride fromalignmentOf(arrSchema)rather thanalignmentOf(elementType).- Tests — added nested-alignment coverage in
disarray.test.ts,internal/arrayBufferIO.noEval.test.ts,internal/partialIo.test.ts, andunstruct.test.ts.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
pkg.pr.new packages benchmark commit |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the one commit added since the prior pullfrog review (f7ddd896, type-only). The TS2322 build break is resolved and no new issues were introduced.
- Typed the shared fallback writer params —
writeStructLikeandwriteArrayLikenow declareInferInput<wgsl.WgslStruct | Unstruct>/InferInput<wgsl.WgslArray | Disarray>instead ofRecord<string, unknown>/readonly unknown[], so thesatisfies CompleteDataWritersassignment accepts the typed-array members ofInferInput. Verified locally:pnpm --filter typegpu test:typesandtsc -p tsconfig.build.json --noEmitboth exit 0.
Prior pullfrog review feedback (the writeArrayLike parameter type) is addressed; the corresponding thread is resolved.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
Bundle size comparison (
|
| 🟢 Decreased (max -0.23%) | ➖ Unchanged | 🔴 Increased (max 0.53%) | ❔ Unknown |
|---|---|---|---|
| 34 | 320 | 1 | 0 |
import * as ... in PR vs import * as ... in target (did bundle size increase?):
| Test | tsdown |
|---|---|
| d_alignmentOf.ts | 29.10 kB ( |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
2fc983f to
346e20f
Compare
346e20f to
0a01cb7
Compare
| }); | ||
|
|
||
| it('reads wgsl structs packed into an unstruct', () => { | ||
| const s = d.unstruct({ a: d.u32, s: d.struct({ v: d.vec3u, w: d.u32 }) }); |
There was a problem hiding this comment.
Could you convince me as to why structs should pack tightly instead of aligning based on the alignment of their natural alignment? Is it because vectors don't either?
iwoplaza
left a comment
There was a problem hiding this comment.
The implementation looks very solid! I am mostly wondering about the behavior, but I am easily persuaded 😆

Changes:
alignmentOfforunstructanddisarray. Now, it recurses into the schema.offsetsForPropsno longer adds trailing padding tounstruct.unstructs.