Drup / ocaml-lmdb

Ocaml bindings for lmdb.
https://drup.github.io/ocaml-lmdb/dev/
MIT License
48 stars 3 forks source link

expose db_val=bigarray, change api to support MDB_RESERVE #10

Closed madroach closed 5 years ago

madroach commented 5 years ago

This pull request includes #9.

It does not yet make use of MDB_RESERVE, since I have not yet merged the changes to the functorial interface.

Performance with this interface exposing db_val as bigarray is better than with CArray, even though my benchmark uses very small 8-byte integers / strings as keys / values

Strangely performance improved yet a bit with commit f0ee7f5, which prepares the interface to support MDB_RESERVE:

val write : (int -> db_val) -> t -> db_val

The write function is passed an allocator, which may simply allocate a bigarray buffer or call a mdb_*_put function with MDB_RESERVE and wrap the returned memory region in a bigarray. If write calls the allocator it is expected to return the allocated bigarray. If write doesn't call the allocator it may return any bigarray and will behave like write in the old interface. So when implementing a write function, one may simply ignore the allocator or always use the allocator and the library will decide when to use or not to use MDB_RESERVE.

Drup commented 5 years ago

Regarding the perf improvements with f0ee7f5 : I'm not completely surprised, as the patch in question make inlining simpler and remove stuff from the closure environment. Avoiding closure capture in OCaml is often a significant perf boost.

Drup commented 5 years ago

The new version using bigstringaf looks really nice. Merging!