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

Remove hyper: Use methods in viz and axum. #2047

Closed
wants to merge 5 commits into from

Conversation

martinfrances107
Copy link
Contributor

hyper 1.0 has been released

-hyper = "0.14.23"
+hyper = "1"

Conventionally 0.x releases are considered pre-releases.
It seems hyper is acting in this vein.

here is the relevant blogs post, which is linked in the release notes.

stability-promise

@martinfrances107
Copy link
Contributor Author

I have found googling the solution to this stuff troublesome

So I'm just making notes for myself, that will also be useful in review.

upgrading guide.. to 1.0

Also this change log

contains this pivotal sentence

The free functions hyper::body::to_bytes and aggregate have been removed. Similar functionality is on http_body_util::BodyExt::collect.

@martinfrances107
Copy link
Contributor Author

martinfrances107 commented Nov 22, 2023

This is a experimental PR.

At two places in the codebase "A" is converted to "B" - where

A)

let body = body::to_bytes(body).await.unwrap_or_default();

B)

let body = body
        .collect::<Vec<_>>()
        .await
        .into_iter()
        .filter_map(|result| result.ok())
        .collect::<Vec<Bytes>>()
        .concat()
        .into();

The question becomes is this the best use of the new API to convert all
stream chunks into a HTTTP Body while minimising the number of copies/clones.

My current thoughts into_iter() is not free !

and

collect.cocat().into() is cumbersome.

@martinfrances107
Copy link
Contributor Author

Just making notes for myself in public

There is good discussion here about the various ways or iterating over a Result type. The strategies to handle the error type.

https://doc.rust-lang.org/rust-by-example/error/iter_result.html#fail-the-entire-operation-with-collect

@martinfrances107
Copy link
Contributor Author

Cool, we now have a base line -- a change that passes tests

I am still worried about the performance implications here.

Regarding clones and copies .. I am not sure this is bad, indifference or a good change

Please be aware I am still thinking about this ... I will ask on discord in the morning if there are any standard ways the gauge a suspected performance regressions.

@martinfrances107
Copy link
Contributor Author

martinfrances107 commented Nov 23, 2023

To justify that last change

hyper is a low level API and we are now accessing that functionality through the viz module, or through the axum module. Modules on which we directly depend.

From a maintenance perspective this is a good change, less dependencies to track.

@martinfrances107 martinfrances107 changed the title hyper has first release. Bumping to version "1". Remove hyper: Use methods in viz and axum. Nov 23, 2023
@dgsantana
Copy link
Contributor

You can check my PR #2082, it moves everything to http 1.0 and axum 0.7. It uses the http-body-util to get the bytes in a easier way. Right now all examples, except for the one which depends on axum_js_fetch is converted. This examples also requires an update on gloo-net, for which I made a PR, let's see if it gets merged.

PS: For Viz, you can't move to http 1.0, because Viz hasn't update yet to hyper 1 and http 1. We need to wait a bit. Maybe make a PR for it?

@martinfrances107
Copy link
Contributor Author

Thanks, StreamBody and BoxBody -- leads to a much cleaner solution

PS: For Viz, you can't move to http 1.0, because Viz hasn't update yet to hyper 1 and http 1. We need to wait a bit. Maybe make a PR for it?

I will help out on that where possible.

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