@@ -1297,13 +1297,17 @@ func (ev *evaluator) VectorBinop(op ItemType, lhs, rhs Vector, matching *VectorM
1297
1297
// signatureFunc returns a function that calculates the signature for a metric
1298
1298
// ignoring the provided labels. If on, then the given labels are only used instead.
1299
1299
func signatureFunc (on bool , names ... string ) func (labels.Labels ) uint64 {
1300
- // TODO(fabxc): ensure names are sorted and then use that and sortedness
1301
- // of labels by names to speed up the operations below.
1302
- // Alternatively, inline the hashing and don't build new label sets.
1300
+ sort .Strings (names )
1303
1301
if on {
1304
- return func (lset labels.Labels ) uint64 { return lset .HashForLabels (names ... ) }
1302
+ return func (lset labels.Labels ) uint64 {
1303
+ h , _ := lset .HashForLabels (make ([]byte , 0 , 1024 ), names ... )
1304
+ return h
1305
+ }
1306
+ }
1307
+ return func (lset labels.Labels ) uint64 {
1308
+ h , _ := lset .HashWithoutLabels (make ([]byte , 0 , 1024 ), names ... )
1309
+ return h
1305
1310
}
1306
- return func (lset labels.Labels ) uint64 { return lset .HashWithoutLabels (names ... ) }
1307
1311
}
1308
1312
1309
1313
// resultMetric returns the metric for the given sample(s) based on the Vector
@@ -1503,6 +1507,8 @@ func (ev *evaluator) aggregation(op ItemType, grouping []string, without bool, p
1503
1507
}
1504
1508
}
1505
1509
1510
+ sort .Strings (grouping )
1511
+ buf := make ([]byte , 0 , 1024 )
1506
1512
for _ , s := range vec {
1507
1513
metric := s .Metric
1508
1514
@@ -1516,9 +1522,9 @@ func (ev *evaluator) aggregation(op ItemType, grouping []string, without bool, p
1516
1522
groupingKey uint64
1517
1523
)
1518
1524
if without {
1519
- groupingKey = metric .HashWithoutLabels (grouping ... )
1525
+ groupingKey , buf = metric .HashWithoutLabels (buf , grouping ... )
1520
1526
} else {
1521
- groupingKey = metric .HashForLabels (grouping ... )
1527
+ groupingKey , buf = metric .HashForLabels (buf , grouping ... )
1522
1528
}
1523
1529
1524
1530
group , ok := result [groupingKey ]
0 commit comments