Repository navigation
Conversation
Replaces the JS implementation of 'use gpu' functions with a stub that keeps the original arity. On the first CPU call, the stub recreates the function from its AST with `reviveFunction` (typegpu/~internal), using `new Function`.
unstable_stripJsImpl
|
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 [1.02, 2.04, 4.26, 6.91, 7.73, 12.34, 26.03, 25.71]
line [1.01, 2.11, 4.57, 6.79, 8.12, 13.43, 26.98, 27.17]
line [0.93, 1.90, 4.18, 6.75, 7.70, 12.85, 26.06, 26.00]
---
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.35, 0.59, 0.74, 0.88, 1.25, 1.26, 1.60, 1.76]
line [0.33, 0.54, 0.74, 0.95, 1.21, 1.26, 1.51, 1.67]
line [0.27, 0.50, 0.72, 0.87, 1.21, 1.19, 1.41, 1.57]
---
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.82, 2.23, 3.53, 6.98, 13.68, 29.17, 57.82, 121.85]
line [0.98, 2.30, 3.77, 7.13, 13.52, 28.55, 61.65, 122.73]
line [0.82, 2.10, 3.43, 7.05, 12.85, 26.73, 56.49, 113.94]
|
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased | ❔ Unknown |
|---|---|---|---|
| 0 | 352 | 0 | 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every
'use gpu'function ships twice: as its JS implementation, and as its AST in the metadata. The JS implementation is only needed when the function is called on the CPU, which most of them never are.With
unstable_stripJsImpl: true, the plugin replaces the implementation with a stub. The first time the stub is called, it recreates the function from the AST.reviveFunction(intypegpu/~internal) prints the AST back to JS withtseynit, rewrites+ - * / %into__tsover_*calls like the plugin does, and builds the function withnew Function. Externals that are property paths (config.nested.offset) become nested objects.reviveFunctiononly into modules that contain stubs, so apps that don't enable the option pay nothing..length. TypeGPU relies on it:createGuardedComputePipelineinfers its dimensionality fromcallback.length. An earlier prototype with a(...args)stub silently changed jelly-slider's compute shader from@workgroup_size(16, 16, 1)to(1, 1, 1).'use gpu'directive, so later plugin passes leave them alone.Caveats, which is why it's opt-in and
unstable_:new Functionrequires a CSP that allows'unsafe-eval'.Measurements
Same four apps and setup as #3246 (lab in #3248). Compared against #3246 with the option off (bytes, minified / gzip / brotli):
Together with
unstable_obfuscate+unstable_minify, gzip drops by another 2,356–8,900 B compared to those options alone. The compressed gains are much larger than #3246's, because the removed JS is information the AST already holds, rather than syntax gzip can compress.With the option off, bundles are byte-identical to #3246's.
Checks:
'use gpu'functions on the CPU (vector operators, dotted externals, destructured params, loops) and prints their WGSL. The output is identical with and without the option, also with obfuscation.main's.