-
Notifications
You must be signed in to change notification settings - Fork 312
Open
Labels
Description
Summary
avoid interface{} allocation
Desired Behaviour
when val is a string and call to truncateStringValueIfLong, if not truncated, no create a new interface{}
if str, ok := val.(string); ok {
val = interface{}(truncateStringValueIfLong(str))
}
func truncateStringValueIfLong(val string) string {
if len(val) > attributeValueLengthLimit {
return stringLengthByteLimit(val, attributeValueLengthLimit)
}
return val
}
Possible Solution
truncateStringValueIfLong maybe return if apply truncate or not
I create an approch solution.
Benchmark with success case without truncate
BenchmarkValidateUserAttribute
BenchmarkValidateUserAttribute/alloc
BenchmarkValidateUserAttribute/alloc-8 75147321 15.60 ns/op 16 B/op 1 allocs/op
BenchmarkValidateUserAttribute/no_alloc
BenchmarkValidateUserAttribute/no_alloc-8 487201981 2.426 ns/op 0 B/op 0 allocs/op