perf(bindings): zero-copy VectorAssignByteElement; legacy []byte copy unchanged#84
Merged
taniabogatsch merged 4 commits intoMay 28, 2026
Conversation
2 tasks
Use duckdb_bind_varchar_length, direct slice pointers for blobs and UTF-8 checks, duckdb_create_varchar_length, and vector assign length APIs. Add micro-benchmarks and TestCreateVarcharEmpty.
f272498 to
c92882c
Compare
Contributor
Author
Contributor
Author
|
@mlafeldt please review :-) |
Document VectorAssignUTF8Bytes wrapper and prove VectorAssignStringElementLen does not allocate in Go on the hot path (no C.CBytes).
VectorAssignStringElementLen restores C.CBytes (safe for reused slices). New VectorAssignByteElement and fixed UnsafeVectorAssignStringElementLen provide zero-copy []byte assign for opt-in callers (duckdb.AppendBytes).
2 tasks
adubovikov
added a commit
to adubovikov/duckdb-go
that referenced
this pull request
May 18, 2026
Plain []byte in AppendRow keeps VectorAssignStringElementLen (C.CBytes copy). AppendBytes / AppendBytesUnsafe opt into VectorAssignByteElement when available in duckdb-go-bindings (requires duckdb/duckdb-go-bindings#84). json.RawMessage in setJSON maps to AppendBytesUnsafe.
Comment on lines
+1349
to
+1350
| length := C.int(StringTLength(*strT)) | ||
| // duckdb_string_t_length takes duckdb_string_t by value; duckdb_string_t_data takes a pointer. | ||
| length := C.int(C.duckdb_string_t_length(*strT)) |
Member
There was a problem hiding this comment.
Why are we changing this? Is the function call into StringTLength confirmed to cause overhead? I would've expected the compiler to catch this - I'll revert this in my commit.
Member
There was a problem hiding this comment.
If I am not mistaken, then this file only adds helpers that are not strictly speaking bindings for the existing API. I'll remove them.
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
High-frequency bind/vector paths for
duckdb-goAppender workloads:VectorAssignStringElementLen([]byte)still copies viaC.CBytes(safe when the Go slice is reused).VectorAssignByteElement— zero-copy UTF-8 assign (duckdb_vector_assign_string_element_len+ slice pointer).UnsafeVectorAssignStringElementLen— zero-copy, no UTF-8 validation (true borrow; was incorrectly copying viaC.CBytesbefore).BindVarchar/BindBlob/CreateBlob: avoidC.CString/C.CByteswhere the C API accepts length + pointer.UTF8Bytes/UnsafeUTF8Bytesmarker types +VectorAssignUTF8Byteshelper.TestVectorAssignByteElement_zeroGoAllocPerAssign.Part 2/4 of perf series; depends on #83.
Companion: duckdb/duckdb-go#138 (
AppendBytes/AppendBytesUnsafein Appender).Test plan
go test ./...bindings_alloc_bench_test.gobenchmarks