aantron / luv

Cross-platform asynchronous I/O and system calls
https://aantron.github.io/luv
MIT License
276 stars 26 forks source link

Consider using a record based `Buffer.t` to represent iovecs for cheaper `sub` operation #124

Open anuragsoni opened 3 years ago

anuragsoni commented 3 years ago

It might be nice to represent Buffer.t using a record as opposed to a straight up bigstring. ex:

type bigstring = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
type t = { buf: bigstring; pos: int; len: int}

In some simple benchmarks in the past i've noticed the sub operation to be a little faster for the record based representation, than using the sub operation from Bigarray.Array1.

┌─────────────────┬──────────┬─────────┬────────────┐
│ Name            │ Time/Run │ mWd/Run │ Percentage │
├─────────────────┼──────────┼─────────┼────────────┤
│ Iovec           │   2.55ns │   4.00w │     10.96% │
│ Bigstringaf.sub │  23.25ns │   7.00w │    100.00% │
└─────────────────┴──────────┴─────────┴────────────┘

Potentially relevent discussion: https://discuss.ocaml.org/t/hannes-mehnert-interview-about-mirageos-and-ocaml-by-evrone/5784/10

talex5 commented 3 years ago

Any chance of using Cstruct.t for this? Would save copying between all the various versions of this type. Eio is already wrapping luv buffers in cstructs.

aantron commented 3 years ago

There is a chance, but I haven't had time to evaluate the various options yet.