Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize serialization of []any and map[string]any #617

Open
wants to merge 7 commits into
base: 5.0
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions neo4j/internal/bolt/outgoing.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,27 @@ func (o *outgoing) packV(v reflect.Value) {
}
case reflect.Struct:
o.packStruct(v.Interface())
case reflect.Slice:
switch v.Type().Elem().Kind() {
case reflect.Uint8:
o.packer.Bytes(v.Bytes())
return
case reflect.Int, reflect.Int64, reflect.String, reflect.Float64, reflect.Interface:
robsdedude marked this conversation as resolved.
Show resolved Hide resolved
if v.Len() > 5 {
robsdedude marked this conversation as resolved.
Show resolved Hide resolved
// Accept the cost of an allocation (v.Interface())
// because this slice type is optimized in packX.
// The exact length from which the optimization amortizes
// the allocation cost depends on many factors.
// 5 is an arbitrary guess.
o.packX(v.Interface())
return
}
}
num := v.Len()
o.packer.ArrayHeader(num)
for i := 0; i < num; i++ {
o.packV(v.Index(i))
}
default:
o.packX(v.Interface())
}
Expand Down