feat: Logger - #2747
Conversation
|
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 [0.97, 2.00, 4.35, 6.73, 7.39, 11.90, 22.13, 25.88]
line [0.97, 1.89, 4.11, 6.77, 8.03, 11.89, 23.40, 23.25]
line [0.98, 2.00, 4.46, 6.61, 8.11, 11.32, 22.26, 25.94]
---
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.31, 0.53, 0.68, 0.85, 1.14, 1.21, 1.44, 1.57]
line [0.30, 0.52, 0.70, 0.87, 1.16, 1.20, 1.47, 1.62]
line [0.32, 0.58, 0.74, 0.85, 1.19, 1.24, 1.48, 1.73]
---
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.81, 2.12, 3.76, 6.94, 12.49, 25.73, 55.27, 112.03]
line [0.75, 2.05, 4.08, 6.82, 12.89, 26.17, 54.66, 111.75]
line [1.00, 2.09, 4.16, 6.72, 13.11, 27.21, 57.87, 118.40]
|
Bundle size comparison (
|
| 🟢 Decreased (max -0.75%) | ➖ Unchanged | 🔴 Increased (max 2.16%) | ❔ Unknown |
|---|---|---|---|
| 1 | 36 | 285 | 0 |
import * as ... in PR vs import * as ... in target (did bundle size increase?):
Click to reveal the results table (202 entries).
| Test | tsdown |
|---|---|
| d_bool.ts | 13.49 kB ( |
| d_f16.ts | 13.49 kB ( |
| d_f32.ts | 13.49 kB ( |
| d_i32.ts | 13.49 kB ( |
| d_u32.ts | 13.49 kB ( |
| d_u16.ts | 13.51 kB ( |
| d_textureDepth2d.ts | 13.93 kB ( |
| d_textureDepthCube.ts | 13.94 kB ( |
| d_texture1d.ts | 13.94 kB ( |
| d_texture2d.ts | 13.94 kB ( |
| d_texture3d.ts | 13.94 kB ( |
| d_textureCube.ts | 13.95 kB ( |
| d_textureDepth2dArray.ts | 13.95 kB ( |
| d_textureDepthCubeArray.ts | 13.96 kB ( |
| d_textureDepthMultisampled2d.ts | 13.96 kB ( |
| d_texture2dArray.ts | 13.96 kB ( |
| d_textureCubeArray.ts | 13.97 kB ( |
| d_textureMultisampled2d.ts | 13.97 kB ( |
| std_isBeingTranspiled.ts | 14.88 kB ( |
| std_getTargetShaderLanguage.ts | 14.94 kB ( |
| std_extensionEnabled.ts | 15.00 kB ( |
| std_range.ts | 15.26 kB ( |
| std_discard.ts | 14.78 kB ( |
| d_disarrayOf.ts | 15.43 kB ( |
| std_copy.ts | 15.02 kB ( |
| std_arrayLength.ts | 15.03 kB ( |
| std_dpdx.ts | 15.74 kB ( |
| std_dpdxCoarse.ts | 15.75 kB ( |
| std_dpdxFine.ts | 15.75 kB ( |
| std_dpdy.ts | 15.75 kB ( |
| std_dpdyCoarse.ts | 15.75 kB ( |
| std_dpdyFine.ts | 15.75 kB ( |
| std_fwidth.ts | 15.75 kB ( |
| std_fwidthCoarse.ts | 15.75 kB ( |
| std_fwidthFine.ts | 15.75 kB ( |
| std_atomicLoad.ts | 16.54 kB ( |
| std_atomicStore.ts | 16.55 kB ( |
| std_textureBarrier.ts | 16.55 kB ( |
| std_atomicAdd.ts | 16.55 kB ( |
| std_atomicAnd.ts | 16.55 kB ( |
| std_atomicMax.ts | 16.55 kB ( |
| std_atomicMin.ts | 16.55 kB ( |
| std_atomicOr.ts | 16.55 kB ( |
| std_atomicSub.ts | 16.55 kB ( |
| std_atomicXor.ts | 16.55 kB ( |
| std_storageBarrier.ts | 16.55 kB ( |
| std_workgroupBarrier.ts | 16.55 kB ( |
| d_vec2b.ts | 19.93 kB ( |
| d_vec2f.ts | 19.93 kB ( |
| d_vec2h.ts | 19.93 kB ( |
| d_vec2i.ts | 19.93 kB ( |
| d_vec2u.ts | 19.93 kB ( |
| d_vec3b.ts | 19.93 kB ( |
| d_vec3f.ts | 19.93 kB ( |
| d_vec3h.ts | 19.93 kB ( |
| d_vec3i.ts | 19.93 kB ( |
| d_vec3u.ts | 19.93 kB ( |
| d_vec4b.ts | 19.93 kB ( |
| d_vec4f.ts | 19.93 kB ( |
| d_vec4h.ts | 19.93 kB ( |
| d_vec4i.ts | 19.93 kB ( |
| d_vec4u.ts | 19.93 kB ( |
| d_formatToWGSLType.ts | 21.43 kB ( |
| d_uint8.ts | 21.43 kB ( |
| d_float16.ts | 21.44 kB ( |
| d_float16x2.ts | 21.44 kB ( |
| d_float16x4.ts | 21.44 kB ( |
| d_float32.ts | 21.44 kB ( |
| d_float32x2.ts | 21.44 kB ( |
| d_float32x3.ts | 21.44 kB ( |
| d_float32x4.ts | 21.44 kB ( |
| d_sint16.ts | 21.44 kB ( |
| d_sint16x2.ts | 21.44 kB ( |
| d_sint16x4.ts | 21.44 kB ( |
| d_sint32.ts | 21.44 kB ( |
| d_sint32x2.ts | 21.44 kB ( |
| d_sint32x3.ts | 21.44 kB ( |
| d_sint32x4.ts | 21.44 kB ( |
| d_sint8.ts | 21.44 kB ( |
| d_sint8x2.ts | 21.44 kB ( |
| d_sint8x4.ts | 21.44 kB ( |
| d_snorm16.ts | 21.44 kB ( |
| d_snorm16x2.ts | 21.44 kB ( |
| d_snorm16x4.ts | 21.44 kB ( |
| d_snorm8.ts | 21.44 kB ( |
| d_snorm8x2.ts | 21.44 kB ( |
| d_snorm8x4.ts | 21.44 kB ( |
| d_uint16.ts | 21.44 kB ( |
| d_uint16x2.ts | 21.44 kB ( |
| d_uint16x4.ts | 21.44 kB ( |
| d_uint32.ts | 21.44 kB ( |
| d_uint32x2.ts | 21.44 kB ( |
| d_uint32x3.ts | 21.44 kB ( |
| d_uint32x4.ts | 21.44 kB ( |
| d_uint8x2.ts | 21.44 kB ( |
| d_uint8x4.ts | 21.44 kB ( |
| d_unorm10_10_10_2.ts | 21.44 kB ( |
| d_unorm16.ts | 21.44 kB ( |
| d_unorm16x2.ts | 21.44 kB ( |
| d_unorm16x4.ts | 21.44 kB ( |
| d_unorm8.ts | 21.44 kB ( |
| d_unorm8x2.ts | 21.44 kB ( |
| d_unorm8x4.ts | 21.44 kB ( |
| d_unorm8x4_bgra.ts | 21.44 kB ( |
| d_packedFormats.ts | 21.45 kB ( |
| d_isPackedData.ts | 21.50 kB ( |
| d_alignmentOf.ts | 22.38 kB ( |
| std_subgroupAdd.ts | 24.88 kB ( |
| std_subgroupAll.ts | 24.89 kB ( |
| std_subgroupAnd.ts | 24.89 kB ( |
| std_subgroupAny.ts | 24.89 kB ( |
| std_subgroupBallot.ts | 24.89 kB ( |
| std_subgroupBroadcast.ts | 24.89 kB ( |
| std_subgroupBroadcastFirst.ts | 24.89 kB ( |
| std_subgroupElect.ts | 24.89 kB ( |
| std_subgroupExclusiveAdd.ts | 24.89 kB ( |
| std_subgroupExclusiveMul.ts | 24.89 kB ( |
| std_subgroupInclusiveAdd.ts | 24.89 kB ( |
| std_subgroupInclusiveMul.ts | 24.89 kB ( |
| std_subgroupMax.ts | 24.89 kB ( |
| std_subgroupMin.ts | 24.89 kB ( |
| std_subgroupMul.ts | 24.89 kB ( |
| std_subgroupOr.ts | 24.89 kB ( |
| std_subgroupShuffle.ts | 24.89 kB ( |
| std_subgroupShuffleDown.ts | 24.89 kB ( |
| std_subgroupShuffleUp.ts | 24.89 kB ( |
| std_subgroupShuffleXor.ts | 24.89 kB ( |
| std_subgroupXor.ts | 24.89 kB ( |
| d_sizeOf.ts | 25.16 kB ( |
| d_isContiguous.ts | 25.17 kB ( |
| d_getLongestContiguousPrefix.ts | 25.18 kB ( |
| d_isBuiltin.ts | 25.11 kB ( |
| std_textureDimensions.ts | 26.49 kB ( |
| std_textureGather.ts | 26.49 kB ( |
| std_textureLoad.ts | 26.50 kB ( |
| std_textureSample.ts | 26.50 kB ( |
| std_textureSampleBaseClampToEdge.ts | 26.50 kB ( |
| std_textureSampleBias.ts | 26.50 kB ( |
| std_textureSampleCompare.ts | 26.50 kB ( |
| std_textureSampleCompareLevel.ts | 26.50 kB ( |
| std_textureSampleGrad.ts | 26.50 kB ( |
| std_textureSampleLevel.ts | 26.50 kB ( |
| std_textureStore.ts | 26.50 kB ( |
| d_arrayOf.ts | 26.60 kB ( |
| d_size.ts | 26.85 kB ( |
| d_align.ts | 26.85 kB ( |
| d_location.ts | 26.85 kB ( |
| d_interpolate.ts | 26.85 kB ( |
| d_invariant.ts | 27.22 kB ( |
| std_identity4.ts | 27.55 kB ( |
| d_mat4x4f.ts | 27.55 kB ( |
| d_mat2x2f.ts | 27.55 kB ( |
| d_mat3x3f.ts | 27.55 kB ( |
| std_identity2.ts | 27.55 kB ( |
| std_identity3.ts | 27.55 kB ( |
| std_rotationX4.ts | 27.55 kB ( |
| std_rotationY4.ts | 27.55 kB ( |
| std_rotationZ4.ts | 27.55 kB ( |
| std_scaling4.ts | 27.55 kB ( |
| d_matToArray.ts | 27.68 kB ( |
| std_translation4.ts | 27.55 kB ( |
| d_builtin.ts | 29.06 kB ( |
| std_pack2x16float.ts | 36.59 kB ( |
| std_pack4x8unorm.ts | 36.59 kB ( |
| std_unpack2x16float.ts | 36.59 kB ( |
| std_unpack4x8unorm.ts | 36.59 kB ( |
| common_fullScreenTriangle.ts | 40.89 kB ( |
| common_writeSoA.ts | 41.72 kB ( |
| d_memoryLayoutOf.ts | 42.48 kB ( |
| std_bitcastF32toU32.ts | 47.35 kB ( |
| std_bitcastU32toF32.ts | 47.36 kB ( |
| std_bitcastU32toI32.ts | 47.36 kB ( |
| std_bitcast.ts | 47.36 kB ( |
| std_neg.ts | 49.16 kB ( |
| std_add.ts | 49.17 kB ( |
| std_bitShiftLeft.ts | 49.17 kB ( |
| std_bitShiftRight.ts | 49.17 kB ( |
| std_div.ts | 49.17 kB ( |
| std_mod.ts | 49.17 kB ( |
| std_mul.ts | 49.17 kB ( |
| std_sub.ts | 49.17 kB ( |
| std_rotateX4.ts | 50.00 kB ( |
| std_scale4.ts | 50.00 kB ( |
| std_translate4.ts | 50.00 kB ( |
| std_rotateY4.ts | 50.01 kB ( |
| std_rotateZ4.ts | 50.01 kB ( |
| std_and.ts | 52.75 kB ( |
| std_or.ts | 52.75 kB ( |
| std_all.ts | 52.75 kB ( |
| std_allEq.ts | 52.75 kB ( |
| std_eq.ts | 52.75 kB ( |
| std_lt.ts | 52.75 kB ( |
| std_ne.ts | 52.75 kB ( |
| std_not.ts | 52.75 kB ( |
| std_select.ts | 52.75 kB ( |
| std_any.ts | 52.76 kB ( |
| std_ge.ts | 52.76 kB ( |
| std_gt.ts | 52.76 kB ( |
| std_isCloseTo.ts | 52.76 kB ( |
| std_le.ts | 52.76 kB ( |
| STATIC_common.ts | 57.65 kB ( |
| d_ref.ts | 4.89 kB ( |
import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):
| Test | tsdown |
|---|---|
| tgpu_init.ts | 259.52 kB ( |
| tgpu_initFromDevice.ts | 258.99 kB ( |
| tgpu_resolve.ts | 164.93 kB ( |
| tgpu_resolveWithContext.ts | 164.87 kB ( |
| tgpu_bindGroupLayout.ts | 69.27 kB ( |
| tgpu_mutableAccessor.ts | 66.27 kB ( |
| tgpu_accessor.ts | 66.26 kB ( |
| tgpu_privateVar.ts | 65.61 kB ( |
| tgpu_workgroupVar.ts | 65.60 kB ( |
| tgpu_const.ts | 64.85 kB ( |
| tgpu_fn.ts | 38.45 kB ( |
| tgpu_fragmentFn.ts | 38.45 kB ( |
| tgpu_vertexFn.ts | 38.27 kB ( |
| tgpu_computeFn.ts | 37.97 kB ( |
| tgpu_vertexLayout.ts | 27.08 kB ( |
| tgpu_comptime.ts | 14.77 kB ( |
| tgpu_unroll.ts | 1.66 kB ( |
| tgpu_slot.ts | 1.54 kB ( |
| tgpu_lazy.ts | 1.19 kB ( |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
|
@pullfrog review |
There was a problem hiding this comment.
Important
One bug should be fixed before merge: the warning prefix contains a stray } in tgpuLogger.ts. A couple of smaller cleanups noted inline.
Reviewed changes — Added a central TgpuLogger that categorizes and optionally suppresses warnings, replaced or adjusted existing console.warn/console.error calls, and exposed a warn control API for consumers.
- Added
packages/typegpu/src/tgpuLogger.tswith type-tagged warnings,disable/reset, and dev/prod-mode defaults. - Replaced
console.warncalls across pipeline, resolve, root init, texture, data I/O, and TGSL modules withlogger.warn(...)carrying warning categories. - Added
warnnamed export fromindexNamedExports.ts. - Removed an unintended
console.logfromdata/ref.tsand downgraded someconsole.errorcalls to categorized warnings. - Updated tests to snapshot the new warning prefix format and added
tgpuLogger.test.ts.
⚠️ One console.warn in shared/meta.ts was not migrated
packages/typegpu/src/shared/meta.ts:26 still calls console.warn directly for duplicate-version detection, so it bypasses the new logger and cannot be silenced through warn.disable(...) or controlled by dev/prod defaults. If module-load ordering allows it, route it through logger.warn(...) too.
Technical details
# One console.warn in shared/meta.ts was not migrated
## Affected sites
- `packages/typegpu/src/shared/meta.ts:26` — raw `console.warn` for duplicate TypeGPU version
## Required outcome
- All runtime warnings go through `TgpuLogger` so they respect `warn.disable(...)` and dev/prod defaults.
## Suggested approach
- Import `logger` from `../../tgpuLogger.ts` and replace the `console.warn` call with a categorized warning.
- Verify that importing `tgpuLogger.ts` this early does not create a circular dependency; it currently depends only on `shared/env.ts`.
## Open questions for the human
- Is the duplicate-version warning intentionally left as a raw `console.warn` because it fires before the logger is initialized? If so, document why it is exempted.Kimi K2 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Important
The logger migration is mostly complete, but two call sites need attention: meta.ts still calls console.warn directly, and a previously console.error failure message is now routed through a prod-silenced logger.warn. Addressing them before merge keeps the warning surface consistent.
Reviewed changes — PR #2747 introduces a centralized TgpuLogger/warn API for typed, disableable warnings and migrates existing console.warn calls across pipelines, resolve, IO, and TGSL modules.
- Add
TgpuLoggersingleton inpackages/typegpu/src/tgpuLogger.tswith per-warning-type enable/disable/reset controls and dev/prod warning sets. - Export
warnas public API frompackages/typegpu/src/indexNamedExports.tsand document it inapps/typegpu-docs/src/content/docs/apis/utils.mdx. - Replace
console.warncalls with typedlogger.warn(...)calls in compute/render pipelines, limit checks, indirect-buffer validation, resolution, texture mipmaps, data IO, compiled IO, TGSL conversion, and console-log generation. - Replace one warn with
invariantfor the emptyrestrictToarray case intgsl/conversion.ts.
⚠️ Duplicate-version warning in meta.ts bypasses the new logger
The duplicate-version check in packages/typegpu/src/shared/meta.ts:26 still calls console.warn directly. This leaves it un-typed, not disableable via warn.disable(...), and outside the dev/prod filtering policy the rest of the codebase now follows.
Technical details
# Duplicate-version warning in `meta.ts` bypasses the new logger
## Affected sites
- `packages/typegpu/src/shared/meta.ts:26` — duplicate-version warning still calls `console.warn` directly.
## Required outcome
- This warning should be emitted through the centralized `logger` so it participates in the type/disable/reset/prod-filtering scheme, or the author should confirm it is intentionally exempt.
## Suggested approach
- Import `logger` from `./tgpuLogger.ts` in `meta.ts`.
- Pick a suitable warning type (e.g. `suspicious`) or introduce a new type if the team wants it visible in production.
- If it must always fire in production, add that type to `TgpuLogger`'s prod-enabled set and explain why it is special.
## Open questions for the human
- Should duplicate-version detection be disableable, or should it always be surfaced?Kimi K2 (free via Pullfrog for OSS) | 𝕏
|
I was suggested to use a system of reverse DNS system, like |

Since the vast majority of our
console.*()wereconsole.warns, I decided to only definelogger.warnand to skip other methods. Let me know if you think this is the right direction for us.