Skip to content

impr: Better d.memoryLayoutOf cache - #3261

Open
cieplypolar wants to merge 4 commits into
fix/loose-schemas-attributesfrom
impr/strideOf
Open

cieplypolar wants to merge 4 commits into
fix/loose-schemas-attributesfrom
impr/strideOf

Conversation

@cieplypolar

Copy link
Copy Markdown
Collaborator

Changes:

  • Introduce strideOf helper
  • Cache intermediate results of computeMemoryLayoutOf

@cieplypolar
cieplypolar added this pull request to stack #3262 October 22, 2026 12:59
Copilot AI balanced review requested due to automatic review settings October 22, 2026 12:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

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.91, 1.84, 3.59, 6.26, 6.47, 9.26, 23.00, 24.03]
  line [0.84, 1.73, 3.83, 5.77, 6.92, 10.18, 22.26, 22.96]
  line [0.92, 1.82, 4.05, 5.72, 6.43, 10.97, 21.32, 23.15]
Loading
---
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.24, 0.48, 0.60, 0.80, 1.04, 1.10, 1.27, 1.46]
  line [0.25, 0.49, 0.68, 0.80, 1.11, 1.13, 1.31, 1.46]
  line [0.25, 0.47, 0.65, 0.77, 1.04, 1.13, 1.33, 1.50]
Loading
---
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.78, 2.06, 3.09, 6.10, 11.43, 23.37, 51.70, 104.07]
  line [0.90, 2.08, 3.80, 6.43, 11.13, 23.01, 52.02, 103.86]
  line [0.79, 2.15, 3.40, 6.49, 11.07, 23.41, 53.20, 104.65]
Loading

@cieplypolar cieplypolar changed the title impr: Better MLO cache impr: Better MemoryLayoutOf cache Oct 22, 2026
@cieplypolar cieplypolar changed the title impr: Better MemoryLayoutOf cache impr: Better d.memoryLayoutOf cache Oct 22, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found — the stride refactor is behavior-preserving and the layout cache is sound.

Reviewed changes

  • strideOf helper — new internal export in schemaMemoryLayout.ts:285 (roundUp(getMemoryLayout(schema.elementType).size, alignmentOf(schema))) consolidating ad-hoc stride math at 8 call sites in writeSoA.ts, webgpuLimitations.ts, vertexLayout.ts, compiledIO.ts, dataIO.ts, offsetUtils.ts, and partialIO.ts.
  • Intermediate layout caching — recursive child calls in computeMemoryLayout now go through the new getMemoryLayout, memoizing into the existing cachedLayouts WeakMap; getLayoutInfo delegates to it.
  • Regression test — tests/internal/schemaMemoryLayoutCache.test.ts pins that a nested schema's custom size is read exactly once.

Behavior is unchanged: alignmentOf(WgslArray) delegates to alignmentOf(elementType) and alignmentOf(Disarray) to customAlignmentOf(elementType) (array/disarray are absent from knownAlignmentMap), so every replaced expression yields the same numeric stride. Verified the full packages/typegpu/tests suite passes (2970 tests across 199 files) and the only tsc --noEmit errors — the dataIO.ts array/disarray writer signature mismatches at lines 264/468 — are pre-existing on the base branch, not introduced here. No public API surface change and no new import cycle.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@61a6a287a40b849bc327e4b0697fe1dd418a33a7
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@61a6a287a40b849bc327e4b0697fe1dd418a33a7
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@61a6a287a40b849bc327e4b0697fe1dd418a33a7

benchmark
view benchmark

commit
view commit

@github-actions

Copy link
Copy Markdown

Bundle size comparison (import * as ... in PR vs import * as ... in target):

🟢 Decreased (max -0.18%) ➖ Unchanged 🔴 Increased (max 0.53%) ❔ Unknown
32 320 3 0

import * as ... in PR vs import * as ... in target (did bundle size increase?):

Test tsdown
d_alignmentOf.ts 29.10 kB ($${\color{red}+0.5\%}$$)

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants