Skip to content

Create a noOpInterner in case string interning is disabled #6705

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

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,7 @@ func (i *Ingester) createTSDB(userID string) (*userTSDB, error) {

instanceLimitsFn: i.getInstanceLimits,
instanceSeriesCount: &i.TSDBState.seriesCount,
interner: util.NewLruInterner(),
interner: util.NewLruInterner(i.cfg.LabelsStringInterningEnabled),
labelsStringInterningEnabled: i.cfg.LabelsStringInterningEnabled,

blockRetentionPeriod: i.cfg.BlocksStorageConfig.TSDB.Retention.Milliseconds(),
Expand Down
11 changes: 10 additions & 1 deletion pkg/util/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,21 @@ type Interner interface {

// NewLruInterner returns a new Interner to be used to intern strings.
// The interner will use a LRU cache to return the deduplicated strings
func NewLruInterner() Interner {
func NewLruInterner(enabled bool) Interner {
if !enabled {
return &noOpInterner{}
}
return &pool{
lru: expirable.NewLRU[string, string](maxInternerLruCacheSize, nil, internerLruCacheTTL),
}
}

type noOpInterner struct{}

func (n noOpInterner) Intern(s string) string {
return s
}

type pool struct {
lru *expirable.LRU[string, string]
}
Expand Down
Loading