roc-lang / basic-webserver

A basic webserver in Roc

Home Page:https://roc-lang.github.io/basic-webserver/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve Allocation Handling

bhansconnect opened this issue · comments

Currently we do a lot of allocating when going from rust to roc. I think we can avoid all of this on both sides.

I don't fully understand all of the pieces, but here is roughly how it would work.

Firstly, for all data being passed into roc, we will use seamless slices. This will make it so that the data does not need to be copied into roc data structures. Instead, roc will just reference the data and will never have to free it. That will make it live the entire time of the request though. So that is a tradeoff to think about. Technically more complex schemes could be used to avoid that.

Second, We need to implement the Body and Buf trait on RocList type. That will enable us to hand the roc list off to hyper with hyper reading directly from the list. Again, no need to copy data or reallocate. The implementation should be pretty simple and the same as would be done for a vector of bytes in rust.