-
Notifications
You must be signed in to change notification settings - Fork 57
Improve Binary Serialization in the Code Generator #58
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
Conversation
I'm a big fan of the Code Generator tool, but I noticed the all-in-one pages serialize the game as a JSON array, which can get kind of chunky. This PR swaps the JSON for a base64 string, bringing a `53.35mb` .html down to `21.85mb`. This should help with storage and load-times. Zipping the .html afterwards brings the whole thing down to within 10% of the original game size. bytes <-> base64 conversions adopted from examples on this page: https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa
✅ Deploy Preview for emulatorjs-org ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
Hmm, I notice the .zip files this tool outputs are getting a 0% compression ratio... perhaps we can do better... |
|
Hmmm, I can add a bit of compression before applying the base64 encoding (Final .html size goes from |
This PR adds compression to the generated .html files using the browser's built-in gzip compression/decompression routines. This brings what would have been a `53.35mb` .html on master (or a `21.85mb` .html with EmulatorJS#58 ) down to `16.32mb`. This further compresses down to `12mb` if zipped. Due to the async call needed for this, I made this a separate PR since the structure of the generated .html has changed to only load the emulator after the game data has been decompressed. This is incompatible with the non-single-file-packing code, so it has been removed.
ethanaobrien
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks
allancoding
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works in my tests. Nice!
I'm a big fan of the Code Generator tool, but I noticed the all-in-one pages serialize the game as a JSON array, which can get kind of chunky.
This PR swaps the JSON for a base64 string, bringing a
53.35mb.html down to21.85mb. This should help with storage and load-times.Zipping the .html afterwards brings the whole thing down to within 10% of the original game size, which is nice if your static file server supports archiving like this.
bytes <-> base64 conversions adopted from examples on this page: https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa