[~Bug] The ArcGIS JS API ES modules are bigger than they should be !

977
3
Jump to solution
03-14-2021 09:49 PM
VictorBerchet
Occasional Contributor

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
 
 
0 Kudos
1 Solution

Accepted Solutions
AndyGup
Esri Regular Contributor

Quick follow-up, we've opened an issue to look into minifying the GLSL files. It won't happen immediately, but it's now something that's on our radar, thanks.

View solution in original post

3 Replies
AndyGup
Esri Regular Contributor

@VictorBerchet Thanks for reporting. It looks like the template literals aren't minified. We're taking a look. 

AndyGup
Esri Regular Contributor

Quick follow-up, we've opened an issue to look into minifying the GLSL files. It won't happen immediately, but it's now something that's on our radar, thanks.

VictorBerchet
Occasional Contributor

Thanks a lot Andy for the update.

I don't think there is any rush and it's great to know it will be handled.

0 Kudos