Skip to content

Commit

Permalink
Avoid unnecessary gettimeofday calls during progress update
Browse files Browse the repository at this point in the history
This gives me a 15% speedup at mailbox open time.
  • Loading branch information
gahr authored and flatcap committed Nov 3, 2021
1 parent 8a0f62f commit edc96db
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions progress/progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,18 @@ static bool time_needs_update(const struct Progress *progress, size_t now)
*/
void progress_update(struct Progress *progress, size_t pos, int percent)
{
if (!progress || OptNoCurses)
if (OptNoCurses || !progress || (progress->inc == 0))
return;

const uint64_t now = mutt_date_epoch_ms();
const bool first = (pos == 0); /* always show the first update */

const bool update =
(pos == 0) /* always show the first update */ ||
(pos_needs_update(progress, pos) && time_needs_update(progress, now));
if (!first && !pos_needs_update(progress, pos))
{
return;
}

if ((progress->inc != 0) && update)
const uint64_t now = mutt_date_epoch_ms();
if (first || time_needs_update(progress, now))
{
progress->pos = pos;
progress->timestamp = now;
Expand Down

0 comments on commit edc96db

Please sign in to comment.