diff mbox series

cache: Emit load progress only at integer percentage boundaries

Message ID 20260923141804.2730554-1-ecordonnier@snap.com
State New
Headers show
Series cache: Emit load progress only at integer percentage boundaries | expand

Commit Message

Etienne Cordonnier Sept. 23, 2026, 2:18 p.m. UTC
From: Etienne Cordonnier <ecordonnier@snap.com>

The check added in bdd7813d8 ("Show the user progress when loading the
cache") was meant to fire events only on whole percentage boundaries,
which Python 2's integer division provided. Since the move to Python 3,
"/" returns a float that increases on every cache entry, so a progress
event is sent for each of the ~5,000 entries in a typical cached parse.
Use floor division to restore the intended ~100 events.

Cached parse-only startup improved from 5.03s to 4.54s on average across
three alternating runs each.

AI-Generated: Uses OpenAI Codex
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
---
 lib/bb/cache.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/bb/cache.py b/lib/bb/cache.py
index 2361c5684..24bde62a9 100644
--- a/lib/bb/cache.py
+++ b/lib/bb/cache.py
@@ -736,7 +736,7 @@  class MulticonfigCache(Mapping):
                 # we might have calculated incorrect total size because a file
                 # might've been written out just after we checked its size
                 cachesize = current_progress
-            current_percent = 100 * current_progress / cachesize
+            current_percent = 100 * current_progress // cachesize
             if current_percent > previous_percent:
                 previous_percent = current_percent
                 bb.event.fire(bb.event.CacheLoadProgress(current_progress, cachesize),