From 3d34fbcbfb839e99a1255a78cfa344ad373e93f0 Mon Sep 17 00:00:00 2001 From: Nikita Vetoshkin Date: Mon, 5 Sep 2016 14:04:40 +0500 Subject: [PATCH] Lower number of allocation in freelist.reindex() Here is a profile taken etcd. Before: 10924 10924 (flat, cum) 4.99% of Total . . 230: . . 231:// reindex rebuilds the free cache based on available and pending free lists. . . 232:func (f *freelist) reindex() { . . 233: f.cache = make(map[pgid]bool) . . 234: for _, id := range f.ids { 10924 10924 235: f.cache[id] = true . . 236: } . . 237: for _, pendingIDs := range f.pending { . . 238: for _, pendingID := range pendingIDs { . . 239: f.cache[pendingID] = true . . 240: } After: 1 1 (flat, cum) 0.0017% of Total . . 228: f.reindex() . . 229: } . . 230: . . 231:// reindex rebuilds the free cache based on available and pending free lists. . . 232:func (f *freelist) reindex() { 1 1 233: f.cache = make(map[pgid]bool, len(f.ids)) . . 234: for _, id := range f.ids { . . 235: f.cache[id] = true . . 236: } . . 237: for _, pendingIDs := range f.pending { . . 238: for _, pendingID := range pendingIDs { --- freelist.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freelist.go b/freelist.go index 1b7ba91..d32f6cd 100644 --- a/freelist.go +++ b/freelist.go @@ -236,7 +236,7 @@ func (f *freelist) reload(p *page) { // reindex rebuilds the free cache based on available and pending free lists. func (f *freelist) reindex() { - f.cache = make(map[pgid]bool) + f.cache = make(map[pgid]bool, len(f.ids)) for _, id := range f.ids { f.cache[id] = true }