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

Compress the serialized PCD collection during sync if above a threshold size #2197

Merged
merged 3 commits into from
Jan 31, 2025

Conversation

robknight
Copy link
Member

This PR amends the serializeStorage and deserializeStorage to apply gzip compression to the serialized PCD string. By pre-compressing the string, we reduce the size of the plaintext sync blob. This is helpful as compression cannot be applied after the blob has been encrypted.

Testing with pseudo-random data indicates a reduction of 50% in the size of the PCD collection string. We might hope to see better real-world performance as real data will have more repetition (of names, email addresses, public keys, and so on).

@robknight robknight marked this pull request as ready for review January 29, 2025 13:54
import stringify from "fast-json-stable-stringify";
import pako from "pako";
Copy link
Collaborator

@rrrliu rrrliu Jan 29, 2025

Choose a reason for hiding this comment

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

this looks like a pretty big package for our bundle (>1MB) -- any way we could dynamically load via bundle splitting or perhaps use a smaller package?

https://npm-compare.com/fflate,pako

https://packagephobia.com/result?p=pako%402.1.0

Copy link
Member Author

@robknight robknight Jan 29, 2025

Choose a reason for hiding this comment

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

It's already a dependency for passport-ui, where it's used to compress the contents of QR codes (at least in cases where those QR codes contain large data, e.g. proofs). It takes up 46kb of space in the bundle:
image

Since it's already included by passport-ui, the additional cost of using it here is zero.

I think packagephobia is just counting the total size of the package's dist directory, but only one file from that directory is actually used - probably pako.min.js or pako.es5.min.js, both of which are around 46kb in size.

@robknight robknight requested a review from rrrliu January 29, 2025 21:16
@robknight robknight added this pull request to the merge queue Jan 31, 2025
Merged via the queue into main with commit 8474f0d Jan 31, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants