Skip to content

Conversation

juj
Copy link
Collaborator

@juj juj commented Sep 23, 2025

Optimize ENVIRONMENT_IS_WASM_WORKER check when building with Audio Worklets enabled, for a code size saving of 7 bytes.

Before, Closure would emit:

m = "em-ww" == globalThis.name,
n = !!globalThis.AudioWorkletGlobalScope,
n && (m = !0);

Afterwards, it emits

n = !!globalThis.AudioWorkletGlobalScope,
m = "em-ww" == globalThis.name || n,

…rklets enabled, for a code size saving of 7 bytes.

#if WASM_WORKERS
#if AUDIO_WORKLET
var ENVIRONMENT_IS_AUDIO_WORKLET = typeof AudioWorkletGlobalScope !== 'undefined';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use != here to save another byte.

We explicitly use == and != when the type of both the LHS and the RHS can only be strings (as in this case). See #16261 for more on this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR #25351 will cover that part. I'll land 25351 first, and then update this PR on top.

@juj juj enabled auto-merge (squash) September 25, 2025 20:25
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.

2 participants