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
Minify GLSL shaders #13706
base: branch-3.5
Are you sure you want to change the base?
Minify GLSL shaders #13706
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## branch-3.4 #13706 +/- ##
===========================================
Coverage 92.58% 92.58%
===========================================
Files 325 325
Lines 20729 20729
===========================================
Hits 19192 19192
Misses 1537 1537 |
Are unminified shaders of any use, e.g. for debugging? If not, and I presume this is the case, then I would always minify them. So, I would move the minification function to |
Also for reference, we always minify generated CSS from |
Yes they are. If you write an invalid shader that fails to compile on the GPU you get an error report in the browser console with the line number of the error. You would still see that when using a minified shader but it would be harder to work out which line number it corresponds to in the original unminified shader. |
I see. Ideally this would be handled via a source map, but that's a lot of work and it's probably not worth it in this case. Let's proceed with this PR. |
@mattpap what do you want to do with this PR? It looks like it could be merged with a trivial MyPy fix. |
Not yet. The minified shaders are not used in CI so we could be generating and shipping garbage without knowing it. |
Fixes #13335.
This minifies the WebGL shaders, mostly by removing comments and unnecessary whitespace. Example of shader before minifying:
and after:
Bundle sizes on
branch-3.4
:and after this PR:
so it saves 17.8 KB of the
gl-min
bundles, about 8.7%.I looked at existing NPM packages for this and didn't find any I liked. Mostly they are unmaintained and tightly coupled to webpack. So I wrote my own as a sequence of regex replacements. These should by understandable by anyone (including my future self) with some regex knowledge. The multiple passes of each shader, one per regex, are probably not very quick but GLSL is such a small fraction of the BokehJS codebase that there isn't any measurable increase in build time on my dev machine.
In future we could extend the minifying to replace local function and variable names with smaller strings, but that would require storing state so would need a different implementation.
Testing is a problem. I think that the visual baseline tests use the unminified bundles so this will not be tested by CI. Could you confirm this @mattpap?