impr: console and Math method reference checks#2438
Conversation
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:
📋 All resultsClick to reveal the results table (350 entries).
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 [0.86, 1.64, 3.56, 5.43, 5.89, 8.88, 18.88, 20.03]
line [0.81, 1.62, 3.21, 5.44, 6.31, 9.96, 18.33, 20.61]
line [0.82, 1.68, 3.63, 5.22, 6.08, 9.14, 17.79, 20.42]
---
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.48, 0.57, 0.74, 1.01, 1.01, 1.27, 1.37]
line [0.31, 0.48, 0.62, 0.69, 0.98, 0.99, 1.26, 1.37]
line [0.28, 0.52, 0.67, 0.80, 1.06, 1.11, 1.60, 1.44]
---
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.73, 1.75, 3.20, 5.19, 10.39, 21.75, 48.07, 95.73]
line [0.83, 1.60, 3.33, 5.32, 10.11, 24.00, 46.71, 94.23]
line [0.75, 1.80, 3.22, 5.37, 10.56, 22.00, 48.85, 95.60]
|
There was a problem hiding this comment.
Pull request overview
This PR refactors JS built-in handling in the TGSL WGSL generator so Math.* and console.* calls are recognized by function reference instead of object identity checks, which is intended to support upcoming expanded externals handling (#2425).
Changes:
- Replaced direct
target === Math/consolemember-access special cases with call-time detection based on function references. - Moved Math/console polyfill metadata into a new
jsPolyfills.tsmodule and updated log-related types to use function references. - Updated console-log tests to expect throws for unsupported console features instead of warning-based fallbacks.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/typegpu/tests/tgsl/consoleLog.test.ts | Updates console logging behavior expectations for unsupported features. |
| packages/typegpu/src/tgsl/wgslGenerator.ts | Refactors Math/console detection from member access to call-time function-reference handling. |
| packages/typegpu/src/tgsl/math.ts | Removes old string-keyed Math mapping module. |
| packages/typegpu/src/tgsl/jsPolyfills.ts | Introduces centralized Math and console function-reference mappings. |
| packages/typegpu/src/tgsl/generationHelpers.ts | Tightens generateLog typing to supported console function refs. |
| packages/typegpu/src/tgsl/consoleLog/types.ts | Switches log metadata/types from string op names to function refs. |
| packages/typegpu/src/tgsl/consoleLog/logGenerator.ts | Updates log generation to accept typed console function refs. |
| packages/typegpu/src/tgsl/consoleLog/deserializers.ts | Replays logs by invoking stored console function refs directly. |
| packages/typegpu/src/resolutionCtx.ts | Propagates the new typed generateLog signature. |
| packages/typegpu/src/data/dataTypes.ts | Removes the old ConsoleLog wrapper type and related imports. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
iwoplaza
left a comment
There was a problem hiding this comment.
Great change, thanks! 🙌
Prerequisite for #2425
This PR removes the
=== consoleand=== Mathchecks fromwgslGenerator.ts, since they will fail when we expand externals to e.g.{ 'console' : { 'log': /* getter */ console.log } }