detached be07ff2

perf(favicon): defer PNG save to idle callback to avoid UI blocking

commit
be07ff20e6e1abddaa7d536bbfa9b263c0a4c169
author
bnema · · 2026-01-06 19:13 UTC
parent
13a022b
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +30 -18
M internal/ui/adapter/favicon.go +30 -18
@@ -192,33 +192,45 @@ func (a *FaviconAdapter) StoreFromWebKitWithOrigin(
192192 }
193193
194194 // saveFaviconToDisk exports a favicon texture to PNG and ensures disk cache is populated.
195+// Uses glib.IdleAdd to defer disk I/O until GTK main loop is idle, avoiding UI blocking.
195196 func (a *FaviconAdapter) saveFaviconToDisk(ctx context.Context, domain string, texture *gdk.Texture) {
196197 log := logging.FromContext(ctx)
197198
198- // Export as PNG for CLI tools (rofi/fuzzel) - do this on main thread
199- // since GTK texture operations need to happen there
199+ // Check if PNG save is needed before scheduling idle callback
200200 pngPath := a.service.DiskPathPNG(domain)
201- if pngPath != "" && !a.service.HasPNGOnDisk(domain) {
202- // Ensure cache directory exists before SaveToPng (GTK won't create it)
201+ needsPNGSave := pngPath != "" && !a.service.HasPNGOnDisk(domain)
202+
203+ if needsPNGSave {
204+ // Ensure cache directory exists (cheap check, do it now)
203205 if err := a.service.EnsureCacheDir(); err != nil {
204206 log.Warn().Err(err).Str("domain", domain).Msg("failed to create favicon cache dir")
205- } else if ok := texture.SaveToPng(pngPath); !ok {
206- log.Warn().Str("domain", domain).Str("path", pngPath).Msg("failed to save favicon PNG")
207- } else {
208- log.Debug().Str("domain", domain).Str("path", pngPath).Msg("saved favicon PNG")
209-
210- // Create normalized sized copy for dmenu/fuzzel (async)
211- // The original PNG is now on disk, so this should succeed
212- go func() {
213- if err := a.service.EnsureSizedPNG(ctx, domain, favicon.NormalizedIconSize); err != nil {
214- log.Warn().Err(err).Str("domain", domain).Msg("failed to create sized PNG")
215- } else {
216- log.Debug().Str("domain", domain).Msg("created sized PNG")
217- }
218- }()
207+ needsPNGSave = false
219208 }
220209 }
221210
211+ if needsPNGSave {
212+ // Schedule PNG save for when GTK main loop is idle (non-blocking)
213+ // texture.SaveToPng must run on main thread but we defer it to avoid blocking
214+ cb := glib.SourceFunc(func(_ uintptr) bool {
215+ if ok := texture.SaveToPng(pngPath); !ok {
216+ log.Warn().Str("domain", domain).Str("path", pngPath).Msg("failed to save favicon PNG")
217+ } else {
218+ log.Debug().Str("domain", domain).Str("path", pngPath).Msg("saved favicon PNG")
219+
220+ // Create normalized sized copy for dmenu/fuzzel (async)
221+ go func() {
222+ if err := a.service.EnsureSizedPNG(ctx, domain, favicon.NormalizedIconSize); err != nil {
223+ log.Warn().Err(err).Str("domain", domain).Msg("failed to create sized PNG")
224+ } else {
225+ log.Debug().Str("domain", domain).Msg("created sized PNG")
226+ }
227+ }()
228+ }
229+ return false // don't repeat
230+ })
231+ glib.IdleAdd(&cb, 0)
232+ }
233+
222234 // Ensure disk cache is populated (async, in background)
223235 go a.service.EnsureDiskCache(ctx, domain)
224236 }
@@ -192,33 +192,45 @@ func (a *FaviconAdapter) StoreFromWebKitWithOrigin(
192 }192 }
193 193
194 // saveFaviconToDisk exports a favicon texture to PNG and ensures disk cache is populated.194 // saveFaviconToDisk exports a favicon texture to PNG and ensures disk cache is populated.
195+// Uses glib.IdleAdd to defer disk I/O until GTK main loop is idle, avoiding UI blocking.
195 func (a *FaviconAdapter) saveFaviconToDisk(ctx context.Context, domain string, texture *gdk.Texture) {196 func (a *FaviconAdapter) saveFaviconToDisk(ctx context.Context, domain string, texture *gdk.Texture) {
196 log := logging.FromContext(ctx)197 log := logging.FromContext(ctx)
197 198
198- // Export as PNG for CLI tools (rofi/fuzzel) - do this on main thread199+ // Check if PNG save is needed before scheduling idle callback
199- // since GTK texture operations need to happen there
200 pngPath := a.service.DiskPathPNG(domain)200 pngPath := a.service.DiskPathPNG(domain)
201- if pngPath != "" && !a.service.HasPNGOnDisk(domain) {201+ needsPNGSave := pngPath != "" && !a.service.HasPNGOnDisk(domain)
202- // Ensure cache directory exists before SaveToPng (GTK won't create it)202+
203+ if needsPNGSave {
204+ // Ensure cache directory exists (cheap check, do it now)
203 if err := a.service.EnsureCacheDir(); err != nil {205 if err := a.service.EnsureCacheDir(); err != nil {
204 log.Warn().Err(err).Str("domain", domain).Msg("failed to create favicon cache dir")206 log.Warn().Err(err).Str("domain", domain).Msg("failed to create favicon cache dir")
205- } else if ok := texture.SaveToPng(pngPath); !ok {207+ needsPNGSave = false
206- log.Warn().Str("domain", domain).Str("path", pngPath).Msg("failed to save favicon PNG")
207- } else {
208- log.Debug().Str("domain", domain).Str("path", pngPath).Msg("saved favicon PNG")
209-
210- // Create normalized sized copy for dmenu/fuzzel (async)
211- // The original PNG is now on disk, so this should succeed
212- go func() {
213- if err := a.service.EnsureSizedPNG(ctx, domain, favicon.NormalizedIconSize); err != nil {
214- log.Warn().Err(err).Str("domain", domain).Msg("failed to create sized PNG")
215- } else {
216- log.Debug().Str("domain", domain).Msg("created sized PNG")
217- }
218- }()
219 }208 }
220 }209 }
221 210
211+ if needsPNGSave {
212+ // Schedule PNG save for when GTK main loop is idle (non-blocking)
213+ // texture.SaveToPng must run on main thread but we defer it to avoid blocking
214+ cb := glib.SourceFunc(func(_ uintptr) bool {
215+ if ok := texture.SaveToPng(pngPath); !ok {
216+ log.Warn().Str("domain", domain).Str("path", pngPath).Msg("failed to save favicon PNG")
217+ } else {
218+ log.Debug().Str("domain", domain).Str("path", pngPath).Msg("saved favicon PNG")
219+
220+ // Create normalized sized copy for dmenu/fuzzel (async)
221+ go func() {
222+ if err := a.service.EnsureSizedPNG(ctx, domain, favicon.NormalizedIconSize); err != nil {
223+ log.Warn().Err(err).Str("domain", domain).Msg("failed to create sized PNG")
224+ } else {
225+ log.Debug().Str("domain", domain).Msg("created sized PNG")
226+ }
227+ }()
228+ }
229+ return false // don't repeat
230+ })
231+ glib.IdleAdd(&cb, 0)
232+ }
233+
222 // Ensure disk cache is populated (async, in background)234 // Ensure disk cache is populated (async, in background)
223 go a.service.EnsureDiskCache(ctx, domain)235 go a.service.EnsureDiskCache(ctx, domain)
224 }236 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close