Skip to content

Commit

Permalink
sane initial cap for buffers
Browse files Browse the repository at this point in the history
prepend and append = 128
filler = 256
  • Loading branch information
vbauerster committed Mar 31, 2024
1 parent 675a6a2 commit eda3fdc
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"github.com/vbauerster/mpb/v8/decor"
)

// buffer capacity allocated per bar structure (prepend|filler|append)
const initialStructBufCap = 256
const defaultRefreshRate = 150 * time.Millisecond

// DoneError represents use after `(*Progress).Wait()` error.
Expand Down Expand Up @@ -467,9 +465,9 @@ func (s pState) makeBarState(total int64, filler BarFiller, options ...BarOption
}
}

for i := 0; i < len(bs.buffers); i++ {
bs.buffers[i] = bytes.NewBuffer(make([]byte, 0, initialStructBufCap))
}
bs.buffers[0] = bytes.NewBuffer(make([]byte, 0, 128)) // prepend
bs.buffers[1] = bytes.NewBuffer(make([]byte, 0, 128)) // append
bs.buffers[2] = bytes.NewBuffer(make([]byte, 0, 256)) // filler

return bs
}

0 comments on commit eda3fdc

Please sign in to comment.