tsdb/index.Symbols: Drop context argument from Lookup method (#13058)

Drop context argument from tsdb/index.Symbols.Lookup since lookup
should be fast and the context checking is a performance hit.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen 2023-11-08 13:08:33 +01:00 committed by GitHub
parent 252c7ca939
commit ae9221e152
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 9 deletions

View file

@ -923,7 +923,7 @@ func (w *Writer) writePostingsToTmpFiles() error {
// Symbol numbers are in order, so the strings will also be in order. // Symbol numbers are in order, so the strings will also be in order.
slices.Sort(values) slices.Sort(values)
for _, v := range values { for _, v := range values {
value, err := w.symbols.Lookup(w.ctx, v) value, err := w.symbols.Lookup(v)
if err != nil { if err != nil {
return err return err
} }
@ -1295,7 +1295,7 @@ func NewSymbols(bs ByteSlice, version, off int) (*Symbols, error) {
return s, nil return s, nil
} }
func (s Symbols) Lookup(ctx context.Context, o uint32) (string, error) { func (s Symbols) Lookup(o uint32) (string, error) {
d := encoding.Decbuf{ d := encoding.Decbuf{
B: s.bs.Range(0, s.bs.Len()), B: s.bs.Range(0, s.bs.Len()),
} }
@ -1307,9 +1307,6 @@ func (s Symbols) Lookup(ctx context.Context, o uint32) (string, error) {
d.Skip(s.offsets[int(o/symbolFactor)]) d.Skip(s.offsets[int(o/symbolFactor)])
// Walk until we find the one we want. // Walk until we find the one we want.
for i := o - (o / symbolFactor * symbolFactor); i > 0; i-- { for i := o - (o / symbolFactor * symbolFactor); i > 0; i-- {
if ctx.Err() != nil {
return "", ctx.Err()
}
d.UvarintBytes() d.UvarintBytes()
} }
} else { } else {
@ -1441,7 +1438,7 @@ func (r *Reader) lookupSymbol(ctx context.Context, o uint32) (string, error) {
if s, ok := r.nameSymbols[o]; ok { if s, ok := r.nameSymbols[o]; ok {
return s, nil return s, nil
} }
return r.symbols.Lookup(ctx, o) return r.symbols.Lookup(o)
} }
// Symbols returns an iterator over the symbols that exist within the index. // Symbols returns an iterator over the symbols that exist within the index.

View file

@ -519,7 +519,6 @@ func TestNewFileReaderErrorNoOpenFiles(t *testing.T) {
} }
func TestSymbols(t *testing.T) { func TestSymbols(t *testing.T) {
ctx := context.Background()
buf := encoding.Encbuf{} buf := encoding.Encbuf{}
// Add prefix to the buffer to simulate symbols as part of larger buffer. // Add prefix to the buffer to simulate symbols as part of larger buffer.
@ -542,11 +541,11 @@ func TestSymbols(t *testing.T) {
require.Equal(t, 32, s.Size()) require.Equal(t, 32, s.Size())
for i := 99; i >= 0; i-- { for i := 99; i >= 0; i-- {
s, err := s.Lookup(ctx, uint32(i)) s, err := s.Lookup(uint32(i))
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, string(rune(i)), s) require.Equal(t, string(rune(i)), s)
} }
_, err = s.Lookup(ctx, 100) _, err = s.Lookup(100)
require.Error(t, err) require.Error(t, err)
for i := 99; i >= 0; i-- { for i := 99; i >= 0; i-- {