chore: reduce string allocations in TSI series cache#27255
chore: reduce string allocations in TSI series cache#27255davidby-influx merged 2 commits intomaster-1.xfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Optimizes TagValueSeriesIDCache.Put to reduce repeated []byte→string conversions by converting measurement/tag key/tag value to string once and reusing the results during insertion.
Changes:
- Convert
name,key, andvaluetostringonce inPut. - Reuse the converted strings for both the cache element fields and map key lookups/inserts.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tsdb/index/tsi1/cache.go
Outdated
| // Convert once; the same string backing array is shared between | ||
| // the cache element (used during eviction) and the map keys. | ||
| nameStr := string(name) | ||
| keyStr := string(key) | ||
| valueStr := string(value) |
There was a problem hiding this comment.
Put now reuses nameStr/keyStr/valueStr for insertion, but it still calls c.exists(name, key, value) beforehand, which converts the same []byte values to string again and allocates. To realize the allocation reduction described in the PR, consider performing the existence check using these already-converted strings (e.g., inline the lookup in Put or add an existsString(nameStr, keyStr, valueStr) helper) so each []byte→string conversion happens only once per Put.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
eliminate string allocations in TSI series cache (cherry picked from commit 37b3100)
Reduce string allocations in
TagValueSeriesIDCache.PutPutconvertsname,key, andvaluefrom[]bytetostringmultiple timesEach
string([]byte)allocates a new backing array, so every entry storedduplicate copies of the same strings.
This converts each
[]bytetostringonce and reuses the result.Cuts allocations per
Putfrom 4-6 down to 3 and eliminateslen(name) + len(key) + len(value)bytes of duplicated heap data per entry.