I was looking at my generated JS after I switched to the ES modules.
It was all nicely minified until I reached code like:
`),e.fragment.uniforms.add("ovInnerColorTex","sampler2D"),e.fragment.uniforms.add("ovOuterColorTex","sampler2D"),e.fragment.uniforms.add("overlayOpacity","float"),e.fragment.code.add(PG`
vec4 getOverlayColor(sampler2D ov0Tex, sampler2D ov1Tex, vec4 texCoords) {
// read textures outside of conditions, to avoid artifacts likely related to non-uniform flow control:
// - https://www.khronos.org/opengl/wiki/Sampler_(GLSL)#Non-uniform_flow_control
// - https://devtopia.esri.com/WebGIS/arcgis-js-api/issues/13657
vec4 color0 = texture2D(ov0Tex, texCoords.xy);
vec4 color1 = texture2D(ov1Tex, texCoords.zw);
float valid0 = float((texCoords.x >= 0.0) && (texCoords.x <= 1.0) && (texCoords.y >= 0.0) && (texCoords.y <= 1.0));
float valid1 = float((texCoords.z >= 0.0) && (texCoords.z <= 1.0) && (texCoords.w >= 0.0) && (texCoords.w <= 1.0));
// Pick color0 if valid, otherwise color1 if valid, otherwise vec4(0)
return mix(color1 * valid1, color0, valid0);
}
This code is from
@Anonymous User/core/views/3d/webgl-engine/core/shaderLibrary/terrain/Overlay.glsl.js
You can notice several things:
1) There are useless (in prod) comments,
2) Each code line start with 6 useless spaces,
3) Longer than needed variable names (color0, valid0 could be c, v).
1 and 2 should be easier to fix. Fixing 3 would need to be able to parse webGL and minify it - maybe there are existing plugins ?
It is hard to evaluate the extra payload needed to be downloaded but I would evaluate it to a few percents looking at my JS output. I really think it would be worth looking into this savings.
I tried to manually minify the code above. It went from 786 to 259B - that's a 3x saving (of course not all code is webGL).
Any thought from the ESRI team ?
Thanks,
Vic