[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: Binding mdb_set_compare with Go
Bryan Matsuo wrote:
openldap-technical,
I am working on some Go (golang) bindings[1] for the LMDB library and I have
some interest in exposing the functionality of mdb_set_compare (and
mdb_set_dupsort). But it is proving difficult and I have a question about the
function(s).
Calling mdb_set_compare from the Go runtime is challenging. Using C APIs with
callbacks comes with restrictions[2][3]. I believe it impossible to bind these
functions way that is flexible, as one would expect. A potential change to
LMDB that would make binding drastically easier is having MDB_cmp_func to take
a third "context" argument with type void*. Then a binding could safely use an
arbitrary Go function for comparisons.
Is it possible for future versions of LMDB to add a third argument to the
MDB_cmp_func signature? Otherwise would it be acceptable for a variant API to
be added using a different function type, one accepting three arguments?
This is a recurrent question.
http://www.openldap.org/its/index.cgi/Incoming?id=8276
http://www.openldap.org/its/index.cgi/Incoming?id=8124
http://www.openldap.org/its/index.cgi/Incoming?id=7980
My response now is the same as before - see ITS#8124 for example.
The compare functions are on the critical path for performance. Jumping thru a
bunch of interpreter glue layers to invoke them is a really bad idea.
I might be convinced if someone were to post some benchmarks showing that an
implementation of an MDB_cmp_func in their chosen language is actually tolerable.
Thanks for the consideration.
Cheers,
- Bryan
[1] Go bindings -- https://github.com/bmatsuo/lmdb-go
[2] Cgo pointer restrictions --
https://github.com/golang/proposal/blob/master/design/12416-cgo-pointers.md
[3] Cgo documentation -- https://golang.org/cmd/cgo/
--
-- Howard Chu
CTO, Symas Corp. http://www.symas.com
Director, Highland Sun http://highlandsun.com/hyc/
Chief Architect, OpenLDAP http://www.openldap.org/project/