Skip to content

feat(@typegpu/prune): Precompile TypeGPU code at build time - #3303

Draft
iwoplaza wants to merge 4 commits into
mainfrom
feat/typegpu-prune
Draft

iwoplaza wants to merge 4 commits into
mainfrom
feat/typegpu-prune

Conversation

@iwoplaza

@iwoplaza iwoplaza commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Adds @typegpu/prune: wrap TypeGPU code in precompile(() => ...), and in production builds it's compiled at build time, so TypeGPU doesn't ship in the bundle.

const boids = precompile((root) => {
  // schemas, shaders, pipelines...
  const render = (format: GPUTextureFormat) =>
    root.createRenderPipeline({ /* ... */ targets: { format } });
  return { params, simulate, bgra: render('bgra8unorm'), rgba: render('rgba8unorm') };
});

const root = await init();
const gpu = boids(root);
  • In dev, the arrow runs on full TypeGPU as usual.
  • In prod, the plugin runs the arrow in Node and replaces it with WGSL, layouts and generated buffer codecs, plus a small runtime.
  • Values only known at runtime (like the canvas format) are precompiled as variants that share their WGSL.
  • Boids example: 91.4 KiB → 5.4 KiB gzipped, with the same GPU calls (tested against a mock device).

Also adds buildReader next to buildWriter, and a stripLogs log option to TypeGPU.

Draft: textures, immediates and some other features aren't supported yet.

@github-actions

github-actions Bot commented Nov 1, 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/tgpu-gen@f12212b1957674688242fb54726dd9d136737b5e
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@f12212b1957674688242fb54726dd9d136737b5e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@f12212b1957674688242fb54726dd9d136737b5e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/color@f12212b1957674688242fb54726dd9d136737b5e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@f12212b1957674688242fb54726dd9d136737b5e
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@f12212b1957674688242fb54726dd9d136737b5e

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Nov 1, 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.98, 2.03, 4.56, 6.50, 7.79, 13.06, 24.45, 25.23]
  line [0.92, 1.82, 3.91, 6.43, 7.56, 11.60, 24.78, 25.80]
  line [0.94, 1.89, 4.05, 5.93, 7.30, 11.58, 21.28, 23.32]
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.27, 0.53, 0.70, 0.86, 1.14, 1.14, 1.40, 1.59]
  line [0.34, 0.52, 0.71, 0.82, 1.12, 1.16, 1.37, 1.45]
  line [0.30, 0.46, 0.65, 0.81, 1.02, 1.11, 1.36, 1.49]
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.98, 2.11, 4.44, 7.31, 14.72, 25.46, 54.88, 113.14]
  line [0.90, 2.14, 4.06, 6.93, 12.43, 26.05, 57.02, 113.15]
  line [0.89, 2.14, 3.42, 6.73, 11.84, 25.40, 54.78, 108.13]
Loading

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

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

🟢 Decreased ➖ Unchanged 🔴 Increased (max 0.06%) ❔ Unknown
0 349 6 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.

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.

1 participant