Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Compress shader source code #12477

Merged
merged 2 commits into from
Jul 25, 2018
Merged

Compress shader source code #12477

merged 2 commits into from
Jul 25, 2018

Conversation

jfirebaugh
Copy link
Contributor

Reduce binary size by compressing shader source, and decompressing at startup. I split it into two commits to see the difference between compressing each program individually versus compressing the entire corpus at once. The latter is significantly better.

@mb12
Copy link

mb12 commented Jul 25, 2018

@jfirebaugh On most platforms the final application package is already compressed. The compression is run on all native libraries (incl mapbox-gl.so) and any resources. Any static data added by shader sources will be compressed with other static data, resulting in lower .apk size.

Can you check the sample application .apk size with and without these? There should be little to no difference. Infact the .apk size might be slightly higher with these changes since the compression algorithm would find fewer redundancies with pre-compressed shaders.

@jfirebaugh
Copy link
Contributor Author

mapbox-gl.so is uncompressed on disk at install time though, so this is still worthwhile.

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

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

This looks good to me.

I'm not very familiar w the tradeoffs involved w compression/decompression, but are there any drawbacks to decompressing the entire shader corpus for each individual shader with the call to source()? Would decompressing once and then individual shaders referencing the same saved decompressed corpus be possible?

@jfirebaugh
Copy link
Contributor Author

Would decompressing once and then individual shaders referencing the same saved decompressed corpus be possible?

This is what's currently implemented -- the corpus contains a null byte between each program, so that each shader can be a const char * pointing to the start location within the corpus.

We could potentially implement a strategy where only the programs that are used are decompressed, but this would require additional complexity, like an archive format that allows file-by-file decompression. Probably not worth it.

@jfirebaugh jfirebaugh merged commit 10e4ea0 into master Jul 25, 2018
@jfirebaugh jfirebaugh deleted the compress-shaders branch July 25, 2018 18:39
@friedbunny
Copy link
Contributor

On iOS, a size report for an empty app with our dynamic framework shows that this change has virtually no effect on the compressed app size (i.e., what a user will first download) and a small effect on the uncompressed app size (what is stored on a user’s device).

Compressed App Uncompressed App
Uncompressed Shaders 1798.63 kB 5095.10 kB
Compressed Shaders 1798.21 kB 5028.74 kB
-0.43 kB -66.34 kB

This is in line with expectations, I’d say.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants