Bryan Matsuo wrote:
I am working on some Go (golang) bindings 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
Calling mdb_set_compare from the Go runtime is challenging. Using C APIs with
callbacks comes with restrictions. 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.
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.
-- Howard Chu
CTO, Symas Corp. http://www.symas.com
Director, Highland Sun http://highlandsun.com/hyc/
Chief Architect, OpenLDAP http://www.openldap.org/project/