go-driver icon indicating copy to clipboard operation
go-driver copied to clipboard

Add additional cursor.ReadDocumentOnly method that does not marshal DocumentMeta

Open irridia opened this issue 5 years ago • 0 comments

In cases where the Document returned by ReadDocument is small (<=500B) the Marshal of DocumentMeta increases the execution time of ReadDocument by ~40%. Even with larger Document sizes, this extra Marshal is a significant portion of execution time (10-20% for even multi-KiB Documents).

Given that the vast majority of use cases that I've seen for cursor.ReadDocument() (and 100% of my use cases over the last couple of years) the meta data isn't used—_, err := cursor.ReadDocument(...)

This change adds a parallel method called ReadDocumentOnly that does not Marshal and return the Meta data, decreasing execution time. For a single call, the difference is in single-digit microseconds, but for hundreds or thousands of returned Documents, the execution time adds up IME.

The method naming could obviously change based on convention or preference of the maintainers. I've also updated v2, though I didn't see relevant v2 unit tests.

Thanks!

irridia avatar Oct 01 '20 02:10 irridia