Potentially faster DB::get by wrapping C++ string

Issue: The RocksDB C++ Get function takes in a std::string pointer. The current C API will copy that into a char array (not null-terminated C string). This copy seems redundant.

To remove this copying, one direction is to have a Go wrapper around a C++ string. Here is my attempt. It seems to work fine.

Previously I was worried about the garbage collection not freeing the C++ string. The solution is to use runtime.SetFinalizer. I verified in a sample run that the C++ string does get deallocated properly when GC runs.

SetFinalizer does look hacky. And the user must not do anything to the read-only data returned from C++ string. If you all are ok with this, I will try integrating it into our RocksDB wrapper code.

Looks like an interesting approach. Remind me to look deeper into this tomorrow. One thing to note is that the value returned from rocksdb needs to be copied over at least once. Because that value is only valid for the life or the callijg function, from what I understand.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.