-
Notifications
You must be signed in to change notification settings - Fork 395
copy: avoid write() when no progress bar needed #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5589308 to
85dfba9
Compare
|
LGTM |
4cc88ac to
d9669bb
Compare
|
The changes look OK to me, but TRAVIS CI isn't happy with them. |
|
@runcom Could you explain this in more detail? What “spikes” in what progress bar (if it goes to What The only thing this PR actually does is avoid calling Or is the important part in avoiding the |
well yeah, I observed that when Discard is used, all the pb stuff were actually called and re-called. This PR basically avoids that as the go profiler showed that as being a busy path. |
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
d9669bb to
0125db9
Compare
mtrmac
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per IRC conversation – the goal seems to be primarily to get rid of the progress bar. I’d be happier with actually finding out what is so expensive about the progress bar, so that users who do use it benefit as well.
But, *shrug*, one extra if in there doesn’t hurt that much. I am a bit concerned about keeping the writer members easy enough to understand.
| reportWriter io.Writer | ||
| writer io.Writer | ||
| reportWriter func(f string, a ...interface{}) | ||
| hasReportWriter bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s not immediately clear what is the difference between writer/reportWriter here. The naming is a bit confusing, as is hasReportWriter for a reportWriter which always exists
And if this is moving all users EDIT to call the function, and the io.Writer is used only for initializing the progress bar, we don’t really need hasReportWriter; we could just have an io.Writer which is either an implementation or nil.
| hasReportWriter = true | ||
| } | ||
|
|
||
| writeReport := func(f string, a ...interface{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| bar.Start() | ||
| destStream = bar.NewProxyReader(destStream) | ||
| defer bar.Finish() | ||
| if ic.hasReportWriter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If making the progress bar conditional is that important for performance, this needs a comment explaining why it is conditional; otherwise in a few months someone will notice that with an ioutil.Discard writer implementation the conditional is redundant and remove it again.
Observed some spikes of the progress bar while writing to
/dev/nullin CRI-O (since it has no progress bar).This PR is a micro-optimization and will avoid a
write()syscall when no progress bar is needed (and to keep the profiler to not show me that writing to /dev/null wastes some micro seconds).@mrunalp @rhatdan @sameo PTAL this is needed by CRI-O post V1
Signed-off-by: Antonio Murdaca runcom@redhat.com