-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Load application favicons without blocking the UI #4889
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
Open
mewclouds
wants to merge
10
commits into
ChrisTitusTech:main
Choose a base branch
from
mewclouds:perf/favicon-loading
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9973d7a
perf: load application favicons in background
mewclouds b6b6a52
perf: add favicon request circuit breaker
mewclouds 1837a8d
fix: preserve favicon state when replacing stale pool
mewclouds 1ea6d99
fix: isolate favicon setup failures
mewclouds 1968542
fix: validate favicon images before reset
mewclouds 9f57161
fix: clean up failed favicon operations
mewclouds 5123cda
Merge remote-tracking branch 'upstream/main' into perf/favicon-loading
mewclouds 79a1b68
perf: defer favicons until app rendering completes
mewclouds d6f5271
refactor: update favicon runspace pool logic for improved concurrency…
mewclouds a0721be
refactor: use runtime processor count for favicon workers
mewclouds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| function Close-WinUtilFaviconRunspacePool { | ||
| <# | ||
| .SYNOPSIS | ||
| Stops favicon work and disposes its timer, operations, circuit breaker, and runspace pool. | ||
| #> | ||
| if ($null -eq $sync) { | ||
| return | ||
| } | ||
|
|
||
| if ($sync.FaviconCircuitBreaker) { | ||
| $sync.FaviconCircuitBreaker.Cancel() | ||
| } | ||
|
|
||
| if ($sync.FaviconTimer) { | ||
| $sync.FaviconTimer.Stop() | ||
| $sync.Remove("FaviconTimer") | ||
| } | ||
|
|
||
| if ($sync.FaviconOperations) { | ||
| foreach ($operation in @($sync.FaviconOperations.Values)) { | ||
| try { | ||
| $operation.PowerShell.Stop() | ||
| } catch { | ||
| } | ||
| try { | ||
| $operation.PowerShell.Dispose() | ||
| } catch { | ||
| } | ||
| } | ||
| $sync.FaviconOperations.Clear() | ||
| } | ||
|
|
||
| if ($sync.FaviconRunspace) { | ||
| try { | ||
| if ($sync.FaviconRunspace.RunspacePoolStateInfo.State -notin @( | ||
| [System.Management.Automation.Runspaces.RunspacePoolState]::Closed, | ||
| [System.Management.Automation.Runspaces.RunspacePoolState]::Closing, | ||
| [System.Management.Automation.Runspaces.RunspacePoolState]::Broken | ||
| )) { | ||
| $sync.FaviconRunspace.Close() | ||
| } | ||
| } finally { | ||
| $sync.FaviconRunspace.Dispose() | ||
| $sync.Remove("FaviconRunspace") | ||
| } | ||
| } | ||
|
|
||
| if ($sync.FaviconCircuitBreaker) { | ||
| $sync.FaviconCircuitBreaker.Dispose() | ||
| $sync.Remove("FaviconCircuitBreaker") | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| function Get-WinUtilFaviconUrl { | ||
| <# | ||
| .SYNOPSIS | ||
| Builds the Google favicon service URL for an application link. | ||
| .PARAMETER Link | ||
| The application website URL whose favicon should be requested. | ||
| #> | ||
| param( | ||
| [Parameter(Mandatory = $true)] | ||
| [string]$Link | ||
| ) | ||
|
|
||
| if ([string]::IsNullOrWhiteSpace($Link)) { | ||
| return $null | ||
| } | ||
|
|
||
| $faviconSize = 64 | ||
| return "https://www.google.com/s2/favicons?sz=$faviconSize&domain_url=$([uri]::EscapeDataString($Link))" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
functions/private/Initialize-WinUtilFaviconRunspacePool.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| function Initialize-WinUtilFaviconRunspacePool { | ||
| <# | ||
| .SYNOPSIS | ||
| Creates or returns the dedicated runspace pool used for favicon downloads. | ||
| .DESCRIPTION | ||
| Uses half the available logical processors while keeping concurrency between | ||
| two and eight workers so favicon requests remain responsive without creating | ||
| an excessive burst of connections. | ||
| #> | ||
| if ($sync.FaviconRunspace -and $sync.FaviconRunspace.RunspacePoolStateInfo.State -eq [System.Management.Automation.Runspaces.RunspacePoolState]::Opened) { | ||
| return $sync.FaviconRunspace | ||
| } | ||
|
|
||
| if ($sync.FaviconRunspace) { | ||
| Close-WinUtilFaviconRunspacePool | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| $minimumWorkers = 2 | ||
| $maximumWorkers = 8 | ||
| $halfProcessors = [Math]::Floor([Environment]::ProcessorCount / 2) | ||
| $maxThreads = [Math]::Max($halfProcessors, $minimumWorkers) | ||
| $maxThreads = [Math]::Min($maxThreads, $maximumWorkers) | ||
| $initialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault() | ||
|
|
||
| $sync.FaviconRunspace = [runspacefactory]::CreateRunspacePool( | ||
| 1, | ||
| $maxThreads, | ||
| $initialSessionState, | ||
| $Host | ||
| ) | ||
| $sync.FaviconRunspace.Open() | ||
| return $sync.FaviconRunspace | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.