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

Custom Brotli Dictionaries #212

Merged
merged 22 commits into from
Mar 21, 2024
Merged

Conversation

rachel-bousfield
Copy link
Contributor

@rachel-bousfield rachel-bousfield commented Mar 16, 2024

Adds support for custom brotli dictionaries, allowing us to dramatically cut Stylus contract sizes.

Resolves STY-67

@cla-bot cla-bot bot added the s label Mar 16, 2024
@rachel-bousfield rachel-bousfield marked this pull request as ready for review March 19, 2024 08:41
Copy link

@mikebenfield mikebenfield left a comment

Choose a reason for hiding this comment

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

Just a couple small remarks.

/// Points to data owned by Go.
ptr: *mut u8,
/// The length in bytes.
len: *mut usize,

Choose a reason for hiding this comment

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

It's not clear to me why the len is also a pointer - couldn't it just be a usize?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added another comment :)

Choose a reason for hiding this comment

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

Ah right; I somehow missed that that actually happened. The comment probably isn't necessary; should be implied by the type; I just missed it.

/// Returns a pointer to a compression-ready instance of the given dictionary.
pub fn ptr(&self, level: u32) -> Option<*const EncoderPreparedDictionary> {
match self {
Self::StylusProgram if level == 11 => Some(STYLUS_PROGRAM_DICT.0),

Choose a reason for hiding this comment

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

Why the check if level == 11? brotli can still use a custom dictionary at lower levels can't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems you need a different dictionary for each level. Ours is a level 11 and that's what cargo stylus uses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You know, we should probs make this return a result given that. I'll add a commit

Copy link

@mikebenfield mikebenfield Mar 21, 2024

Choose a reason for hiding this comment

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

Ah, I see what you mean. The binary dictionary we supply isn't level-specific, but the thing prepared by BrotliEncoderPrepareDictionary is. In that case it seems like maybe we'd want to either allow the possibility to prepare dictionaries at other levels, or else only allow compression at level 11. But I don't have a strong opinion; as-is is fine with me.

Base automatically changed from vm-storage-cache to stylus March 21, 2024 23:11
Copy link

@mikebenfield mikebenfield left a comment

Choose a reason for hiding this comment

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

LGTM; I did leave another couple remarks.

@rachel-bousfield rachel-bousfield merged commit cec7fc4 into stylus Mar 21, 2024
8 checks passed
@rachel-bousfield rachel-bousfield deleted the custom-brotli-dictionaries branch March 21, 2024 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants