Skip to content

impr: Skip uniform alignment analysis when its warning is off - #3238

Merged
iwoplaza merged 1 commit into
mainfrom
impr/skip-disabled-alignment-warning
Oct 21, 2026
Merged

iwoplaza merged 1 commit into
mainfrom
impr/skip-disabled-alignment-warning

Conversation

@iwoplaza

Copy link
Copy Markdown
Collaborator

Every $usage('uniform') walked the schema and computed memory layouts to decide whether to warn about non-portable uniform alignment (uniform-schema-misaligned). That warning is off by default in production builds, so the work was wasted there.

  • Adds isEnabled(type) to the internal logger, so callers can skip computing what a warning needs when it won't be shown.
  • warnIfNotUniformAligned returns early when its warning is disabled. In development and tests nothing changes.

Node 22 with NODE_ENV=production, creating root.createBuffer(Scene).$usage('uniform') for a scene struct (camera matrices plus an array of 16 light structs). Medians of 9 fresh processes:

main this PR
First buffer 1.90 ms 0.45 ms
Each of the next 200 69.2 µs 3.8 µs

@github-actions

github-actions Bot commented Oct 21, 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@4d4f9ddb4f21ec7e83482e1ed5553d776876f5ff
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@4d4f9ddb4f21ec7e83482e1ed5553d776876f5ff

benchmark
view benchmark

commit
view commit

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.

🟢 Approval recommended

The guard respects existing warning configuration, with no blocking issues identified.

No open issues 🎉

What changed in this PR

Avoids unnecessary uniform-alignment analysis when its warning is disabled, reducing production buffer-creation overhead.

Changes:

  • Adds an internal logger query for warning enablement.
  • Skips alignment analysis when disabled while preserving enabled-warning behavior.
File Description
packages/​typegpu/​src/​tgpuLogger.ts Adds isEnabled using current warning state.
packages/​typegpu/​src/​core/​pipeline/​webgpuLimitations.ts Returns early when alignment warnings are disabled.

Review effort: Balanced

@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.

( ◦°^°◦) 🏴‍☠️ Ahoy! I read the whole diff, checked who calls warnIfNotUniformAligned, and made sure the new isEnabled be the only implementer's burden. The ship be seaworthy — no leaks found.

Reviewed changes

  • Skip disabled alignment analysis — warnIfNotUniformAligned now returns early when uniform-schema-misaligned is off, avoiding a full schema walk and layout computation that produced no output in production.
  • Internal Logger.isEnabled — new isEnabled(type) on the Logger interface, implemented on TgpuLogger as #enabledWarnings.has(type).

I verified the output is byte-for-byte identical in every environment (the old logger.warn already no-op'd when the type was disabled), that dev/test keep all warning types enabled so the warning tests still pass, and that TgpuLogger is the only implementer of the non-exported Logger interface. The skipped memoryLayoutOf/alignmentOf/sizeOf calls are pure memoizers with no side effects beyond caching, so eliding them is safe. Nice, well-scoped perf win.

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

@github-actions

github-actions Bot commented Oct 21, 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.84, 1.84, 3.60, 5.50, 6.23, 10.07, 20.19, 19.17]
  line [0.79, 1.54, 3.26, 5.28, 6.68, 9.45, 20.01, 20.53]
  line [0.74, 1.70, 3.36, 5.00, 6.01, 8.44, 18.19, 20.22]
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.23, 0.44, 0.58, 0.71, 1.02, 1.00, 1.22, 1.38]
  line [0.22, 0.44, 0.57, 0.77, 1.00, 0.99, 1.24, 1.36]
  line [0.23, 0.39, 0.57, 0.68, 0.93, 0.91, 1.07, 1.24]
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.67, 1.86, 3.29, 6.06, 11.09, 22.18, 44.37, 96.66]
  line [0.86, 2.06, 3.28, 6.16, 11.13, 22.20, 48.46, 94.29]
  line [0.76, 1.82, 2.86, 5.76, 10.70, 21.01, 48.65, 90.59]
Loading

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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

🟢 Decreased ➖ Unchanged 🔴 Increased (max 0.17%) ❔ Unknown
0 39 316 0

No notable changes.

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

@iwoplaza
iwoplaza force-pushed the impr/skip-disabled-alignment-warning branch 2 times, most recently from 316298f to f7922a6 Compare October 21, 2026 10:14
Comment thread packages/typegpu/src/core/pipeline/webgpuLimitations.ts
@iwoplaza
iwoplaza force-pushed the impr/skip-disabled-alignment-warning branch from f7922a6 to beb7ab4 Compare October 21, 2026 11:09
@iwoplaza
iwoplaza requested a review from cieplypolar October 21, 2026 11:10
@iwoplaza
iwoplaza force-pushed the impr/skip-disabled-alignment-warning branch from beb7ab4 to e31b14a Compare October 21, 2026 11:10

@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.

( ◦°^°◦) 🏴‍☠️ Ahoy! I read the new commit stem to stern — the enablement check be hoisted out o' the recursive walk into its own helper, just as the reviewer asked. No leaks in the hull.

Reviewed changes

  • Guard hoisted out of recursion — warnIfNotUniformAligned now evaluates logger.isEnabled('uniform-schema-misaligned') once and hands the recursive schema walk to a new private checkUniformAlignment helper, so the check no longer re-runs at every array/struct node.

This addresses the review feedback to move the enablement check out of the recursive function. The refactor is behavior-preserving: when the warning is disabled the exported entry point still returns before any traversal; when enabled, checkUniformAlignment performs the same recursion and emits the same warnings as the previous self-recursive warnIfNotUniformAligned. The only caller (packages/typegpu/src/core/buffer/buffer.ts:365) is unaffected, and the helper is module-private.

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

Every `$usage('uniform')` walked the schema and computed memory layouts to decide whether to warn about non-portable uniform alignment (`uniform-schema-misaligned`). That warning is off by default in production builds, so the work was wasted there.

- Adds `isEnabled(type)` to the internal logger, so callers can skip computing what a warning needs when it won't be shown.
- `warnIfNotUniformAligned` returns early when its warning is disabled. In development and tests nothing changes.

Node 22 with `NODE_ENV=production`, creating `root.createBuffer(Scene).$usage('uniform')` for a scene struct (camera matrices plus an array of 16 light structs). Medians of 9 fresh processes:

| | main | this PR |
|---|---|---|
| First buffer | 1.90 ms | 0.45 ms |
| Each of the next 200 | 69.2 µs | 3.8 µs |
@iwoplaza
iwoplaza force-pushed the impr/skip-disabled-alignment-warning branch from e31b14a to 4d4f9dd Compare October 21, 2026 11:56
@iwoplaza
iwoplaza merged commit 7c853fa into main Oct 21, 2026
9 checks passed
@iwoplaza
iwoplaza deleted the impr/skip-disabled-alignment-warning branch October 21, 2026 12:15
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.

3 participants