Repository navigation
feat(unplugin-typegpu): Support obfuscation of already built sources - #3291
cieplypolar wants to merge 6 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 insufficient remaining quota.
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.
|
pkg.pr.new packages benchmark commit |
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased | ❔ Unknown |
|---|---|---|---|
| 0 | 355 | 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.
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.13, 2.22, 4.97, 7.22, 9.36, 13.14, 29.49, 29.08]
line [1.06, 2.17, 4.76, 7.26, 8.59, 13.34, 27.08, 28.63]
line [1.06, 2.26, 4.65, 7.99, 8.48, 14.17, 27.69, 28.80]
---
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.34, 0.61, 0.77, 0.92, 1.28, 1.32, 1.58, 1.74]
line [0.32, 0.52, 0.73, 0.87, 1.20, 1.25, 1.56, 1.71]
line [0.33, 0.56, 0.72, 0.90, 1.23, 1.31, 1.55, 1.71]
---
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.90, 2.49, 4.67, 8.15, 15.06, 29.63, 62.99, 128.71]
line [0.96, 2.20, 4.54, 8.40, 15.22, 28.29, 60.43, 122.03]
line [0.93, 2.53, 3.85, 8.08, 14.63, 28.42, 61.77, 125.87]
|
There was a problem hiding this comment.
ℹ️ No critical issues — one small documentation gap.
Reviewed changes
Reviewed the complete diff of PR #3291 against impr/unplugin-ast-ext-parser (4 commits, 8 files). The PR lets unplugin-typegpu re-obfuscate metadata embedded by an earlier transform pass.
- Re-obfuscation of built functions —
functionOnExitnow runsreobfuscateEmbeddedwhen embedded metadata is present andunstable_obfuscateis on, rewriting the metadataastand the external getter keys through the newreplaceWithObfuscatedmethod (Babel and unplugin implementations). obfuscateAstextraction —obfuscatenow delegates toobfuscateAst(fn, externalKeys), returning the obfuscated AST plus a key map so the same routine can be reused on already-built metadata;sourceMapis preserved.- Early-pruning regex —
earlyPruneRegexbecomesgetEarlyPruneRegex(obfuscate), adding__TYPEGPU_META__as a trigger when obfuscation is enabled so metadata-only files are no longer skipped. - Tests — re-obfuscation of built shellless/shelled functions, idempotency, prune behavior, and the once-per-file unsupported-version warning. All 284 package tests pass; typecheck passes.
ℹ️ earlyPruning docs no longer list every trigger string
The Options.earlyPruning JSDoc still says files are skipped unless they contain "typegpu", "tgpu" or "use gpu". With this change, when unstable_obfuscate is on the trigger set also includes __TYPEGPU_META__, so an already-built file with no directive and no typegpu reference is intentionally no longer pruned. The minifying-shaders guide is likewise silent on the newly re-obfuscated already-built inputs.
Technical details
# Update early-pruning option docs to mention `__TYPEGPU_META__`
## Affected sites
- `packages/unplugin-typegpu/src/core/common.ts:39-46` — `Options.earlyPruning` JSDoc enumerates the trigger strings but predates the `__TYPEGPU_META__` addition in `getEarlyPruneRegex` (`common.ts:168-174`).
- `apps/typegpu-docs/src/content/docs/advanced/minifying-shaders.mdx` — describes `unstable_obfuscate` without noting that already-built sources are now re-obfuscated.
## Required outcome
- Document that when `unstable_obfuscate` is enabled, files containing `__TYPEGPU_META__` are also transformed (not pruned).
## Open questions for the human
- Whether the user-facing guide should call out the re-obfuscation of already-built sources, or whether the flag remains intentionally undocumented until it stabilizes.deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (5c1faa47..386095e6, a docs-only commit) on top of the full PR against impr/unplugin-ast-ext-parser.
- Re-obfuscation documented —
minifying-shaders.mdxgains an:::caution[Experimental]note explaining that already-built sources can be re-processed with{ unstable_obfuscate: true, autoNamingEnabled: false }, and that names from the original build are preserved. - Early-pruning trigger documented — the
earlyPruningJSDoc incore/common.tsand its mirror intooling/unplugin-typegpu.mdxnow both mention that__TYPEGPU_META__counts as a trigger whenunstable_obfuscateis enabled. - Trailing newline —
minifying-shaders.mdxnow ends with a newline.
The documentation gap raised in the prior review is fully addressed. The recommended option pair matches checkOpts (which rejects unstable_obfuscate + autoNamingEnabled together), and the claim that original-build names survive re-obfuscation is consistent with reobfuscateEmbedded, which only rewrites the embedded ast and the externals' keys, leaving metadata.name untouched.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
e605c53 to
2414b52
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (e605c533..2414b524). The range also picks up a base-branch advance (c17c69a8 → 99777d94, "lowering arrow functions" on impr/unplugin-ast-ext-parser); that commit is not part of this PR's diff and was not reviewed here. One authored commit landed on the branch.
- Bun warning context —
bun.tsnow passes{ warn: (message) => console.warn(message) }into the manualrawPlugin.transform.handler.applycall in place of{}. Previouslystate.warnresolved tothis.warnon an empty stub, so the new unsupported-metadata warning thrown during re-obfuscation crashed withthis.warn is not a functionunder Bun. - Regression test —
test/bun.test.tsdowngrades the embedded metadata (v: 2 → v: 1), runs the plugin withunstable_obfuscate, and asserts exactly one warning plus preserved file contents.
Verified locally: vitest run --project=!browser packages/unplugin-typegpu/test/bun.test.ts passes (4 tests) and pnpm --filter unplugin-typegpu test:types is clean. No open pullfrog threads remain on this PR.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
2414b52 to
c860aaa
Compare

No description provided.