Skip to content
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

Shareable prefabs #42

Closed
getkey opened this issue Jan 28, 2021 · 1 comment
Closed

Shareable prefabs #42

getkey opened this issue Jan 28, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@getkey
Copy link
Owner

getkey commented Jan 28, 2021

Using @ErikSom's trick of compressing JSON, then turning it into base64 so prefabs can be shared on Discord.

Let's use https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs as the format.
A good compression algorithm is necessary because Discord's character limit per message is presently 2000.

data:application/bombhopperio-prefab+json;compression=lz-string;base64,NobwRALgngDgpmAXJOAPCYA0YYEMBOuAtgM5LipIBMADDdlEgKy3YDGA9jI4uHAHZIwAFQAWASxIACSVIii4UgCZwAZrgCuAGwhStcAG5wtAQgA6/AKJLxuiBylQOG/HvEBrcfwDmYAL7YuPxsohz45GCUiDQAdEwMSLFMAWBB3vqJfgHg0PBC/GFEuFpYOATEZLxgRvgQ4mxwlaCRSAAsdAmIABy02S2I7fRgPF1dNH1RLEMjYxPMrMNIPeMAutiSAMoQuHVsSBD4GnBZmDmwCMj1CNh4hKQRNbuNSM1RALRUAGzTzLOn/R9vp1lnMBh1Ft1ev8ooNOgB2b6ggCMQIhCPG0KQHx+iE+7VBbyR7U6eNW6xIWx29X2h2OfVyFzAAiUMA4XgwN3K9yqkyYOM+AGYhpttrsaUdsPhxN5RBAAGK4NheXyIA4S1I+DLRE5nPLIGBaXBQODhTl3SoULGonifBZpLXCimi6mIdRaEhwbBFby4ABeXguwDA3nwAlwKlKcCIMGgpQARtp9BgVjrIOd8oViqVbhUHiank1LYgPgLPp0qABOKgEpEI8tVmt1iEClgEqilzot6trMAiql7V3FD1ZFZAA

Tour of the compression algorithms

  • lz-string: works well (sadly operates only on strings, so array buffers need to be turned into strings)
  • lzma: works well, small file size
  • brotli: dependency is too big to include in this project
  • zstd: https://www.npmjs.com/package/zstddec is to be tested, others are too big

My tests

How small can the entities in this level can turn out to be?

The comparisons below are done on base64 strings, close to real-world.

  • json + lz-string: 1712B
  • messagepack + lz-string: 1312B 5ms
  • messagepack + lzma: 872B 77ms

Some naive non-base64 benchmarks (because they all use the default paramters)

615 msgPacked.bin.br
638 msgPacked.bin.zopfli.deflate
644 msgPacked.bin.zopfli.zlib
652 msgPacked.bin.lzma
656 msgPacked.bin.zopfli.gzip
668 msgPacked.bin.lz
682 msgPacked.bin.bz2
690 msgPacked.bin.gz
700 msgPacked.bin.xz
721 msgPacked.bin.lzham
762 msgPacked.bin.zst
1018 msgPacked.bin.lzo
1035 msgPacked.bin.lz4
1065 msgPacked.bin.Z
2464 msgPacked.bin

TL;DR: the lzma module is sturdy and has a good ratio, so let's use that. (but let's make sure the service worker works since it's slow!)

The prefix will be as follow: data:application/vnd.bombhopperio-prefab+msgpack;compression=lzma;base64

@getkey getkey added the enhancement New feature or request label Jan 28, 2021
@getkey
Copy link
Owner Author

getkey commented Mar 8, 2021

Closed by the series of commits leading up to cdcb7d4!

@getkey getkey closed this as completed Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant