Git Product home page Git Product logo

monoio-http's People

Contributors

har23k avatar ihciah avatar porschefanboy avatar rainj-me avatar wisdom-yzh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

monoio-http's Issues

Could not compile `monoio-http` (lib)

error: concrete type differs from previous defining opaque type use
   --> /Users/shabbirhasan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/monoio-http-0.2.3/src/common/body.rs:111:9
    |
111 | /         async move {
112 | |             let buf = self.bytes().await?;
113 | |             match encoding.as_str() {
114 | |                 "gzip" => {
...   |
136 | |             }
137 | |         }
    | |_________^ expected `[async block@/Users/shabbirhasan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/monoio-http-0.2.3/src/common/body.rs:68:9: 83:10]`, got `[async block@/Users/shabbirhasan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/monoio-http-0.2.3/src/common/body.rs:111:9: 137:10]`
    |
note: previous use here
   --> /Users/shabbirhasan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/monoio-http-0.2.3/src/common/body.rs:68:9
    |
68  | /         async move {
69  | |             match self.stream_hint() {
70  | |                 StreamHint::None => Ok(Bytes::new()),
71  | |                 StreamHint::Fixed => self
...   |
82  | |             }
83  | |         }
    | |_________^

error: could not compile `monoio-http` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...    

Decoder improvement

I have a new proposal for the http1 decoder refactor.
Now h1 decoder is a little bit too complicated, and using Framed causes it to allocate and copy memory, which can be avoided.

When Framed decode something, it calls the decoder to decode an item or tell itself that the buffered data is not sufficient. But, the Framed itself does not know at least how much data it should allocate and read, so it may grow buffer and read many times when the body is big. Also, splitting BytesMut makes it hard to reuse the buffer.
Though the Decoder provides a way(buffer.reverse) to save loop{grow, read}, it is really not intuitive and does not guarntee the buffer is filled.
The new proposal is to:

  1. Make Framed/FramedRead impl AsyncReadRent like a ReadBuf. It can be impl as(the ReadBuf follows the same rule):
    1. When ReadBuf has data, copy it.
    2. When ReadBuf has no data, and there is little data to read, read to ReadBuf inner buffer and copy it. -> With a big buffer there will be less read syscall.
    3. When ReadBuf has no data, and there is a lot data to read, read from ReadBuf inner IO. -> Saves memcpy.
  2. When we need fixed length data, read directly from it in async way.
  3. Do not split data from Framed inner buffer in Decoder impl.

The decoder that treats Framed/FramedRead as AsyncReadRent can impl AsyncDecoder of monoio-codec crate. Also, the AsyncDecoder can be improved by changing
fn decode<IO>(&mut self, src: IO) -> Self::DecodeFuture<'_>;
to
fn decode<IO>(&mut self, src: &mut IO) -> Self::DecodeFuture<'_>;

And another thing we can do to monoio-codec is to define a new sync decoder trait, which can tell Framed a more precise hint including the data length.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.