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

Feature/support gzip #30

Closed

Conversation

heisencoder
Copy link

@heisencoder heisencoder commented Nov 23, 2022

See #28 for context.

This new code will serve up br compressed if supported, but will
fall back to gzip compression if not.

This PR is based on the refactoring in #29 .

The gzip support was mostly copied over from PR #22 .

@heisencoder
Copy link
Author

Hi @jakobhellermann and @daxpedda . Please review #29 before this PR. Thanks!

Copy link
Contributor

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

GitHub has this feature for "Draft Pull Request", which is probably appropriate here.
You should probably not ping jakobhellermann, repo owners get notified anyway.

src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
src/wasm_bindgen.rs Outdated Show resolved Hide resolved
@heisencoder heisencoder marked this pull request as draft November 23, 2022 18:45
@heisencoder
Copy link
Author

Thank you @daxpedda for all your constructive comments! I should have some time after U.S. Thanksgiving to take another pass.

Copy link
Author

@heisencoder heisencoder left a comment

Choose a reason for hiding this comment

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

Thanks again for the comments! This is cleaned up a bunch from the previous version.

src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
@heisencoder heisencoder requested a review from daxpedda November 24, 2022 01:34
Copy link
Contributor

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

LGTM.

So I'm not sure what jakobhellermann's policy is, but usually it is encouraged to do proper git rebases instead of merging it like this, makes it easier to reason about the commit flow and therefor review.

This PR extracts the logic from `run_server` that creates a new Router
into a helper function named `get_router` to make it easier to test
without needing to start the full server.

This also adds a simple test that verifies current behavior for
returning a br compressed wasm.wasm file.

This change is in preparation for adding support dynamically change the
available compression.
See jakobhellermann#28 for context.

This new code will serve up br compressed if supported, but will
fall back to gzip compression if not.
@heisencoder
Copy link
Author

I went ahead and rebased this into two commits: one for the refactoring and one for supporting gzip. These commits are otherwise unchanged from the latest versions.

Given that this PR includes the refactoring as a separate commit, I'll go ahead and simplify by closing the refactoring PR and just opening up this for general review.

@heisencoder heisencoder marked this pull request as ready for review November 24, 2022 18:10
@jakobhellermann
Copy link
Owner

Thanks a lot for the PR! I'll give it a proper review over the weekend.

One thing that I don't like though is that this will increase the startup duration for everyone, not just people who have to use #28.

First off, for context, the reason that compression is hand-rolled instead of just slapping a tower_http::Compression middleware on, is that I really want to be able to log a more realistic (and less scary) size of the module, because the difference compression makes can be huge (3.73mb vs 18.83mb, 12.83mb vs 65.38mb).

Now I can see a few solutions:

I don't know yet which I prefer.

@heisencoder
Copy link
Author

I did think about the considerations for increased startup time and thought that maybe using a future for gzip would hide that extra time for users who don't need it. However, if tower_http::compression can take care streaming compression in a layer, then maybe that's the simplest solution. I suspect this would allow for faster server bring-up because the layer could compress the file during the request instead of compressing all of it beforehand. While it's somewhat interesting to see the file size as the server is running, it's also possible to easily get the compressed file size from the browser developer tools.

@daxpedda
Copy link
Contributor

Alternatively we could move Gzip compression to be generated on the fly and leave brotli as it currently is.

@johanhelsing
Copy link
Contributor

I'm currently using this branch because i need to test my app on a phone... Perhaps it could be enabled by setting an env var, or be the default if not binding to localhost?

@heisencoder
Copy link
Author

Hi @jakobhellermann -- any thoughts following-up from your last comment about which approach you'd prefer to get this issue resolved? Thanks! :)

@jakobhellermann
Copy link
Owner

Hi @jakobhellermann -- any thoughts following-up from your last comment about which approach you'd prefer to get this issue resolved? Thanks! :)

honestly I think I should just caring about printing the uncompressed size. I've opened a PR to remove the manual compression and just rely on tower_http::Compression: #41

@jakobhellermann
Copy link
Owner

@johanhelsing do you wanna try if #41 (now merged into main) works for your mobile use case?

@jakobhellermann
Copy link
Owner

According to #28 (comment) the issue is fixed so I'll close this PR

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.

4 participants