stats: escape map keys containing dot (.)#2992
Conversation
sougou
left a comment
There was a problem hiding this comment.
Did we run into a use case that required names to have dots? If not, I think we should avoid this change for the sake of simplicity and performance.
| return t | ||
| } | ||
|
|
||
| var escaper = strings.NewReplacer(".", "\\.", "\\", "\\\\") |
There was a problem hiding this comment.
I think this is going to be very expensive. I believe these functions get called on every query. Can you benchmark the before and after?
There was a problem hiding this comment.
I created a benchmark for MultiCounters:
var benchMultiCounter = NewMultiCounters("benchMulti", []string{"call", "keyspace", "dbtype")
func BenchmarkMultiCounters(b *testing.B) {
clear()
key := []string{"execute-key-ranges", "keyspacename", "replica"}
benchCounter.Add(key, 1)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
benchCounter.Add(key, 1)
}
})
}before:
BenchmarkMultiCounters-3 300000000 186 ns/op
after:
BenchmarkMultiCounters-3 200000000 261 ns/op
So this adds only 75 ns to a 186 ns operation (+40%) in the normal case where there are no dots or backslashes in the key. Even if it ran 100 times per query it would only add 7.5 microseconds. Note that the whole key is already being copied by strings.Join; this is only adding a pass to scan the key for 2 characters.
There was a problem hiding this comment.
Sounds good. I've seen regexp to be more expensive. I guess it's driven by complexity.
|
This creates invalid json. I believe you need to doubly escape them, that is escape the \ as well: |
No description provided.