Skip to content

Optimize -s MIN_WEBGL_VERSION=2 and WebGL context creation #12623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 8, 2020

Conversation

juj
Copy link
Collaborator

@juj juj commented Oct 28, 2020

Micro-optimize WebGL context creation code, and when targeting WebGL 2 only, drop WebGL 1 specific code.

Shrinks tests/minimal_webgl JS code size by 389 bytes, from 4882 bytes to 4493 bytes. (-7.97%).

'preserveDrawingBuffer': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.preserveDrawingBuffer }}}>>2)],
'powerPreference': __emscripten_webgl_power_preferences[powerPreference],
'failIfMajorPerformanceCaveat': !!HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.failIfMajorPerformanceCaveat }}}>>2)]
};
contextAttributes.majorVersion = HEAP32[a + ({{{ C_STRUCTS.EmscriptenWebGLContextAttributes.majorVersion }}}>>2)];
Copy link
Member

Choose a reason for hiding this comment

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

I think you can still add the ones without quotations to the object literal, without quotations? Or does stuff like this confuse closure?

var x = {
  'y': 1,
  z: 2
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed that works.. Oddly that causes Closure to completely oddly change a minification decision afterwards, and it stops optimizing if-else into a ternary ?:, losing whatever bytes it gained from there.

@juj juj force-pushed the optimize_webgl2_only branch from 54e7d77 to 6fb8f4a Compare November 8, 2020 14:08
@juj juj merged commit 38b559c into emscripten-core:master Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants