Skip to content

chore: reduce string allocations in TSI series cache#27255

Merged
davidby-influx merged 2 commits intomaster-1.xfrom
DSB/series_cache_str_alloc
Feb 27, 2026
Merged

chore: reduce string allocations in TSI series cache#27255
davidby-influx merged 2 commits intomaster-1.xfrom
DSB/series_cache_str_alloc

Conversation

@davidby-influx
Copy link
Copy Markdown
Contributor

Reduce string allocations in TagValueSeriesIDCache.Put

Put converts name, key, and value from []byte to string multiple times
Each string([]byte) allocates a new backing array, so every entry stored
duplicate copies of the same strings.

This converts each []byte to string once and reuses the result.
Cuts allocations per Put from 4-6 down to 3 and eliminates
len(name) + len(key) + len(value) bytes of duplicated heap data per entry.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Optimizes TagValueSeriesIDCache.Put to reduce repeated []bytestring conversions by converting measurement/tag key/tag value to string once and reusing the results during insertion.

Changes:

  • Convert name, key, and value to string once in Put.
  • 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.

Comment on lines +112 to +116
// 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)
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 []bytestring conversion happens only once per Put.

Copilot uses AI. Check for mistakes.
devanbenz
devanbenz previously approved these changes Feb 26, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@davidby-influx davidby-influx merged commit 37b3100 into master-1.x Feb 27, 2026
13 checks passed
@davidby-influx davidby-influx deleted the DSB/series_cache_str_alloc branch February 27, 2026 17:00
davidby-influx added a commit that referenced this pull request Feb 27, 2026
eliminate string allocations in TSI series cache

(cherry picked from commit 37b3100)
davidby-influx added a commit that referenced this pull request Feb 27, 2026
eliminate string allocations in TSI series cache

(cherry picked from commit 37b3100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants