mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 09:41:57 +00:00
Optimise merge of LatestMaps with same keys, different timestamps
Swap the two maps so we are merging older into later.
This commit is contained in:
@@ -79,13 +79,17 @@ function generate_latest_map() {
|
||||
// Tries to return one of its inputs, if that already holds the correct result.
|
||||
func (m ${latest_map_type}) Merge(n ${latest_map_type}) ${latest_map_type} {
|
||||
switch {
|
||||
case m == nil:
|
||||
case len(m) == 0:
|
||||
return n
|
||||
case n == nil:
|
||||
case len(n) == 0:
|
||||
return m
|
||||
}
|
||||
if len(n) > len(m) {
|
||||
m, n = n, m //swap so m is always at least as long as n
|
||||
} else if len(n) == len(m) && m[0].Timestamp.Before(n[0].Timestamp) {
|
||||
// Optimise common case where we merge two nodes with the same contents
|
||||
// sampled at different times.
|
||||
m, n = n, m // swap equal-length arrays so first element of m is newer
|
||||
}
|
||||
|
||||
i, j := 0, 0
|
||||
|
||||
@@ -47,13 +47,17 @@ func (m StringLatestMap) Size() int {
|
||||
// Tries to return one of its inputs, if that already holds the correct result.
|
||||
func (m StringLatestMap) Merge(n StringLatestMap) StringLatestMap {
|
||||
switch {
|
||||
case m == nil:
|
||||
case len(m) == 0:
|
||||
return n
|
||||
case n == nil:
|
||||
case len(n) == 0:
|
||||
return m
|
||||
}
|
||||
if len(n) > len(m) {
|
||||
m, n = n, m //swap so m is always at least as long as n
|
||||
} else if len(n) == len(m) && m[0].Timestamp.Before(n[0].Timestamp) {
|
||||
// Optimise common case where we merge two nodes with the same contents
|
||||
// sampled at different times.
|
||||
m, n = n, m // swap equal-length arrays so first element of m is newer
|
||||
}
|
||||
|
||||
i, j := 0, 0
|
||||
@@ -290,13 +294,17 @@ func (m NodeControlDataLatestMap) Size() int {
|
||||
// Tries to return one of its inputs, if that already holds the correct result.
|
||||
func (m NodeControlDataLatestMap) Merge(n NodeControlDataLatestMap) NodeControlDataLatestMap {
|
||||
switch {
|
||||
case m == nil:
|
||||
case len(m) == 0:
|
||||
return n
|
||||
case n == nil:
|
||||
case len(n) == 0:
|
||||
return m
|
||||
}
|
||||
if len(n) > len(m) {
|
||||
m, n = n, m //swap so m is always at least as long as n
|
||||
} else if len(n) == len(m) && m[0].Timestamp.Before(n[0].Timestamp) {
|
||||
// Optimise common case where we merge two nodes with the same contents
|
||||
// sampled at different times.
|
||||
m, n = n, m // swap equal-length arrays so first element of m is newer
|
||||
}
|
||||
|
||||
i, j := 0, 0
|
||||
|
||||
Reference in New Issue
Block a user