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

Add config for compressing options before chrome.sync.set #31

Closed
mjmaurer opened this issue Jul 25, 2019 · 6 comments
Closed

Add config for compressing options before chrome.sync.set #31

mjmaurer opened this issue Jul 25, 2019 · 6 comments

Comments

@mjmaurer
Copy link

mjmaurer commented Jul 25, 2019

Thanks for all these awesome webext libraries!

The sync.set serialization isn't the most transparent, but from what it sounds like it might be something like JSON.stringify

The storage.sync capacity is 100Kb so I think the smaller the better here.

Could use something like lz-string + JSON.stringify to seriazlize + compress / decompress + deserialize the options map

@fregante
Copy link
Owner

fregante commented Jul 25, 2019

The sync.set serialization isn't the most transparent, but from what it sounds like it might be something like JSON.stringify

Indeed, it looks like that's what they're using:

chrome.storage.sync.getBytesInUse(console.log)
// -> 4256

chrome.storage.sync.get(data => console.log(JSON.stringify(data).length))
// -> 4261

This library is pretty small: https://bundlephobia.com/result?p=lz-string@1.4.4

I tried compressing my Refined GitHub options and that number went down to 850 bytes, which is pretty good. It should probably be enabled by default.

The compression takes 7ms on RunKit and the decompression about 2ms.

@mjmaurer
Copy link
Author

sweet! feel free to assign to me. I think I'll have some time

@fregante
Copy link
Owner

Sure, if you have time it would be great. It should probably be enabled by default but it should still be able to read the uncompressed options to allow an easy migration of existing users. Then the options can be compressed on the successive save

@fregante

This comment has been minimized.

@jroehl
Copy link
Contributor

jroehl commented Oct 3, 2019

Hi, first and foremost - thanks for this awesome little package! 👍
As I need this feature for another project - I implemented the compression in #40.

I am using compressToEncodedURIComponent - as I found that the compression rate was actually higher for js objects.

What do you think?

@fregante
Copy link
Owner

Fixed by #40

Available in v1.2.0

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

No branches or pull requests

3 participants