-
Notifications
You must be signed in to change notification settings - Fork 454
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
Significantly improve performance of FetchResultToPromResult and helper functions #1003
Conversation
benchResult *prompb.QueryResult | ||
) | ||
|
||
func BenchmarkFetchResultToPromResult(b *testing.B) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be useful to paste the benchmark results in a comment here just for easier comparisons in the future?
// Perform bulk allocation upfront then convert to pointers afterwards | ||
// to reduce total number of allocations. See BenchmarkFetchResultToPromResult | ||
// if modifying. | ||
timeseries := make([]prompb.TimeSeries, 0, len(result.SeriesList)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice pattern, we can probably make use fo this approach elsewhere too
for i := 0; i < numDatapointsPerSeries; i++ { | ||
values = append(values, ts.Datapoint{ | ||
Timestamp: time.Time{}, | ||
Value: float64(i), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe use a random value and time.Now() instead?
Codecov Report
@@ Coverage Diff @@
## master #1003 +/- ##
=========================================
- Coverage 77.6% 75.21% -2.4%
=========================================
Files 412 407 -5
Lines 34653 34474 -179
=========================================
- Hits 26892 25929 -963
- Misses 5887 6641 +754
- Partials 1874 1904 +30
Continue to review full report at Codecov.
|
src/query/storage/converter.go
Outdated
func SeriesToPromTS(series *ts.Series) prompb.TimeSeries { | ||
labels := TagsToPromLabels(series.Tags) | ||
samples := SeriesToPromSamples(series) | ||
return prompb.TimeSeries{Labels: labels, Samples: samples} | ||
} | ||
|
||
// TagsToPromLabels converts tags to prometheus labels | ||
// TagsToPromLabels converts tags to prometheus labels.TagsToPromLabels. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a find+replace issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
} | ||
var ( | ||
seriesLen = series.Len() | ||
values = series.Values() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we only use these in one place so probably prefer to drop the var for it and just use the accessor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah because then it gets called on every iteration of the loop. Moving these out into vars actually made a significant impact (20%ish percent improvement or so)
}) | ||
} | ||
|
||
samplesPointers := make([]*prompb.Sample, 0, len(samples)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit; alternatively can use seriesLen here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just seemed safer to use the length of the thing I'm actually iterating through
Before
After