fix: restore async webview pool prewarming lost during engine abstraction
PrewarmAsync was not exposed through the port.WebViewPool interface, causing app.go to fall back to synchronous Prewarm which blocked the GTK main thread at cold start.
- commit
- 9591200a482fb5ba54a0b902aa8ad663bc153987
- author
- brice · · 2026-03-17 13:30 UTC
- parent
- 1dcf50c
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +12 -3
M internal/application/port/webview.go +6 -1
| @@ -275,10 +275,15 @@ type WebViewPool interface { | |||
| 275 | 275 | // If the pool is full, the WebView will be destroyed. | |
| 276 | 276 | Release(wv WebView) | |
| 277 | 277 | ||
| 278 | - | // Prewarm creates WebViews in the background to populate the pool. | |
| 278 | + | // Prewarm creates WebViews synchronously to populate the pool. | |
| 279 | 279 | // Pass count <= 0 to use the default prewarm count. | |
| 280 | 280 | Prewarm(count int) | |
| 281 | 281 | ||
| 282 | + | // PrewarmAsync schedules WebView creation on the toolkit idle loop, | |
| 283 | + | // avoiding blocking startup while still warming up WebViews. | |
| 284 | + | // Pass count <= 0 to use the default prewarm count. | |
| 285 | + | PrewarmAsync(ctx context.Context, count int) | |
| 286 | + | ||
| 282 | 287 | // Size returns the current number of available WebViews in the pool. | |
| 283 | 288 | Size() int | |
| 284 | 289 | ||
| @@ -275,10 +275,15 @@ type WebViewPool interface { | |||||
| 275 | // If the pool is full, the WebView will be destroyed. | 275 | // If the pool is full, the WebView will be destroyed. | ||
| 276 | Release(wv WebView) | 276 | Release(wv WebView) | ||
| 277 | 277 | ||||
| 278 | - | // Prewarm creates WebViews in the background to populate the pool. | 278 | + | // Prewarm creates WebViews synchronously to populate the pool. |
| 279 | // Pass count <= 0 to use the default prewarm count. | 279 | // Pass count <= 0 to use the default prewarm count. | ||
| 280 | Prewarm(count int) | 280 | Prewarm(count int) | ||
| 281 | 281 | ||||
| 282 | + | // PrewarmAsync schedules WebView creation on the toolkit idle loop, | |||
| 283 | + | // avoiding blocking startup while still warming up WebViews. | |||
| 284 | + | // Pass count <= 0 to use the default prewarm count. | |||
| 285 | + | PrewarmAsync(ctx context.Context, count int) | |||
| 286 | + | ||||
| 282 | // Size returns the current number of available WebViews in the pool. | 287 | // Size returns the current number of available WebViews in the pool. | ||
| 283 | Size() int | 288 | Size() int | ||
| 284 | 289 | ||||
M internal/infrastructure/webkit/engine_adapters.go +4 -0
| @@ -72,6 +72,10 @@ func (a *webViewPoolAdapter) Prewarm(count int) { | |||
| 72 | 72 | a.pool.Prewarm(a.ctx, count) | |
| 73 | 73 | } | |
| 74 | 74 | ||
| 75 | + | func (a *webViewPoolAdapter) PrewarmAsync(ctx context.Context, count int) { | |
| 76 | + | a.pool.PrewarmAsync(ctx, count) | |
| 77 | + | } | |
| 78 | + | ||
| 75 | 79 | func (a *webViewPoolAdapter) Size() int { | |
| 76 | 80 | return a.pool.Size() | |
| 77 | 81 | } | |
| @@ -72,6 +72,10 @@ func (a *webViewPoolAdapter) Prewarm(count int) { | |||||
| 72 | a.pool.Prewarm(a.ctx, count) | 72 | a.pool.Prewarm(a.ctx, count) | ||
| 73 | } | 73 | } | ||
| 74 | 74 | ||||
| 75 | + | func (a *webViewPoolAdapter) PrewarmAsync(ctx context.Context, count int) { | |||
| 76 | + | a.pool.PrewarmAsync(ctx, count) | |||
| 77 | + | } | |||
| 78 | + | ||||
| 75 | func (a *webViewPoolAdapter) Size() int { | 79 | func (a *webViewPoolAdapter) Size() int { | ||
| 76 | return a.pool.Size() | 80 | return a.pool.Size() | ||
| 77 | } | 81 | } | ||
M internal/ui/app.go +2 -2
| @@ -359,7 +359,7 @@ func (a *App) setupPoolBackgroundColor(ctx context.Context) { | |||
| 359 | 359 | log.Debug().Msg("configured webview pool background color") | |
| 360 | 360 | } | |
| 361 | 361 | ||
| 362 | - | func (a *App) prewarmWebViewPoolAsync(_ context.Context) { | |
| 362 | + | func (a *App) prewarmWebViewPoolAsync(ctx context.Context) { | |
| 363 | 363 | if a.engine == nil { | |
| 364 | 364 | return | |
| 365 | 365 | } | |
| @@ -367,7 +367,7 @@ func (a *App) prewarmWebViewPoolAsync(_ context.Context) { | |||
| 367 | 367 | if pool == nil { | |
| 368 | 368 | return | |
| 369 | 369 | } | |
| 370 | - | pool.Prewarm(0) | |
| 370 | + | pool.PrewarmAsync(ctx, 0) | |
| 371 | 371 | } | |
| 372 | 372 | ||
| 373 | 373 | func (a *App) createMainWindow(ctx context.Context) error { | |
| @@ -359,7 +359,7 @@ func (a *App) setupPoolBackgroundColor(ctx context.Context) { | |||||
| 359 | log.Debug().Msg("configured webview pool background color") | 359 | log.Debug().Msg("configured webview pool background color") | ||
| 360 | } | 360 | } | ||
| 361 | 361 | ||||
| 362 | - | func (a *App) prewarmWebViewPoolAsync(_ context.Context) { | 362 | + | func (a *App) prewarmWebViewPoolAsync(ctx context.Context) { |
| 363 | if a.engine == nil { | 363 | if a.engine == nil { | ||
| 364 | return | 364 | return | ||
| 365 | } | 365 | } | ||
| @@ -367,7 +367,7 @@ func (a *App) prewarmWebViewPoolAsync(_ context.Context) { | |||||
| 367 | if pool == nil { | 367 | if pool == nil { | ||
| 368 | return | 368 | return | ||
| 369 | } | 369 | } | ||
| 370 | - | pool.Prewarm(0) | 370 | + | pool.PrewarmAsync(ctx, 0) |
| 371 | } | 371 | } | ||
| 372 | 372 | ||||
| 373 | func (a *App) createMainWindow(ctx context.Context) error { | 373 | func (a *App) createMainWindow(ctx context.Context) error { | ||