mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-14 10:20:00 +08:00
perf: pre-allocate all known length arrays to avoid re-scaling (#5029)
Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a2b98dbcf7
commit
130e1ba963
@@ -207,7 +207,7 @@ func (c *cluster) getCurrent(key watchKey) []KV {
|
||||
return nil
|
||||
}
|
||||
|
||||
var kvs []KV
|
||||
kvs := make([]KV, 0, len(watcher.values))
|
||||
for k, v := range watcher.values {
|
||||
kvs = append(kvs, KV{
|
||||
Key: k,
|
||||
@@ -308,7 +308,7 @@ func (c *cluster) load(cli EtcdClient, key watchKey) int64 {
|
||||
time.Sleep(coolDownUnstable.AroundDuration(coolDownInterval))
|
||||
}
|
||||
|
||||
var kvs []KV
|
||||
kvs := make([]KV, 0, len(resp.Kvs))
|
||||
for _, ev := range resp.Kvs {
|
||||
kvs = append(kvs, KV{
|
||||
Key: string(ev.Key),
|
||||
@@ -352,7 +352,7 @@ func (c *cluster) reload(cli EtcdClient) {
|
||||
// cancel the previous watches
|
||||
close(c.done)
|
||||
c.watchGroup.Wait()
|
||||
var keys []watchKey
|
||||
keys := make([]watchKey, 0, len(c.watchers))
|
||||
for wk, wval := range c.watchers {
|
||||
keys = append(keys, wk)
|
||||
if wval.cancel != nil {
|
||||
|
||||
Reference in New Issue
Block a user