Skip to content

Commit

Permalink
Removing expvar keys since it's heart performance and it's unused.
Browse files Browse the repository at this point in the history
benchmark                               old ns/op       new ns/op     delta
Benchmark_T1000_P5000_Matches-4         2614306617      10704746      -99.59%
Benchmark_T1000_P5000_NoMatches-4       2515589915      10024400      -99.60%
Benchmark_T100_P5000_Matches-4          33235249        13528192      -59.30%
Benchmark_T100_P5000_NoMatches-4        35301480        2377025       -93.27%
Benchmark_T10_P5000_Matches-4           3999232         2545317       -36.35%
Benchmark_T10_P5000_NoMatches-4         4069072         2356547       -42.09%
Benchmark_T10_P500_CountTask-4          4308417         556166        -87.09%
Benchmark_T10_P500000_CountTask-4       171780120       154546757     -10.03%
Benchmark_T1000_P500-4                  17486595152     15440082      -99.91%
Benchmark_T1000_P500000_CountTask-4     19294813464     318064303     -98.35%

benchmark                               old allocs     new allocs     delta
Benchmark_T1000_P5000_Matches-4         12084          10060          -16.75%
Benchmark_T1000_P5000_NoMatches-4       12083          10061          -16.73%
Benchmark_T100_P5000_Matches-4          1264           1073           -15.11%
Benchmark_T100_P5000_NoMatches-4        1266           1055           -16.67%
Benchmark_T10_P5000_Matches-4           179            155            -13.41%
Benchmark_T10_P5000_NoMatches-4         178            155            -12.92%
Benchmark_T10_P500_CountTask-4          388            336            -13.40%
Benchmark_T10_P500000_CountTask-4       428            385            -10.05%
Benchmark_T1000_P500-4                  32184          27166          -15.59%
Benchmark_T1000_P500000_CountTask-4     32253          27199          -15.67%

benchmark                               old bytes     new bytes     delta
Benchmark_T1000_P5000_Matches-4         1818384       1752617       -3.62%
Benchmark_T1000_P5000_NoMatches-4       1818384       1752675       -3.61%
Benchmark_T100_P5000_Matches-4          1413715       1408155       -0.39%
Benchmark_T100_P5000_NoMatches-4        1413848       1406806       -0.50%
Benchmark_T10_P5000_Matches-4           1373087       1372209       -0.06%
Benchmark_T10_P5000_NoMatches-4         1372988       1372138       -0.06%
Benchmark_T10_P500_CountTask-4          157302        155606        -1.08%
Benchmark_T10_P500000_CountTask-4       149610906     149609495     -0.00%
Benchmark_T1000_P500-4                  1433632       1272199       -11.26%
Benchmark_T1000_P500000_CountTask-4     150886920     150723879     -0.11%
  • Loading branch information
yosiat committed Apr 1, 2016
1 parent 8cad1c0 commit 0ae0360
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions expvar/expvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"expvar"
"fmt"
"math"
"sort"
"strconv"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -79,9 +78,8 @@ func (v *Float) Set(value float64) {

// Map is a string-to-expvar.Var map variable that satisfies the expvar.Var interface.
type Map struct {
mu sync.RWMutex
m map[string]expvar.Var
keys []string // sorted
mu sync.RWMutex
m map[string]expvar.Var
}

func (v *Map) String() string {
Expand All @@ -106,20 +104,6 @@ func (v *Map) Init() *Map {
return v
}

// updateKeys updates the sorted list of keys in v.keys.
// must be called with v.mu held.
func (v *Map) updateKeys() {
if len(v.m) == len(v.keys) {
// No new key.
return
}
v.keys = v.keys[:0]
for k := range v.m {
v.keys = append(v.keys, k)
}
sort.Strings(v.keys)
}

func (v *Map) Get(key string) expvar.Var {
v.mu.RLock()
defer v.mu.RUnlock()
Expand All @@ -130,14 +114,12 @@ func (v *Map) Set(key string, av expvar.Var) {
v.mu.Lock()
defer v.mu.Unlock()
v.m[key] = av
v.updateKeys()
}

func (v *Map) Delete(key string) {
v.mu.Lock()
defer v.mu.Unlock()
delete(v.m, key)
v.updateKeys()
}

func (v *Map) Add(key string, delta int64) {
Expand All @@ -151,7 +133,6 @@ func (v *Map) Add(key string, delta int64) {
if !ok {
av = new(Int)
v.m[key] = av
v.updateKeys()
}
v.mu.Unlock()
}
Expand All @@ -174,7 +155,6 @@ func (v *Map) AddFloat(key string, delta float64) {
if !ok {
av = new(Float)
v.m[key] = av
v.updateKeys()
}
v.mu.Unlock()
}
Expand All @@ -197,8 +177,8 @@ func (v *Map) Do(f func(expvar.KeyValue)) {
// doLocked calls f for each entry in the map.
// v.mu must be held for reads.
func (v *Map) doLocked(f func(expvar.KeyValue)) {
for _, k := range v.keys {
f(expvar.KeyValue{k, v.m[k]})
for k, v := range v.m {
f(expvar.KeyValue{k, v})
}
}

Expand Down

0 comments on commit 0ae0360

Please sign in to comment.