mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-08-09 09:31:15 +10:00
* Add startup performance tracing * Lazy initialize non-default tabs * Render install app entries incrementally * Defer and cache toggle status checks * Clean up runspace invocation ownership * Defer GUI runspace pool startup * Defer status taskbar asset rendering * Record final speed verification * Fix deferred install render timer callback * Add dispatcher smoke coverage for install rendering * Replace install render timer with dispatcher callbacks * Gate performance tracing behind compile switch * Clean up analyzer warnings in speed changes * Speed up runspace and tab initialization
40 lines
1.9 KiB
PowerShell
40 lines
1.9 KiB
PowerShell
function Initialize-WinUtilRunspacePool {
|
|
if ($sync.runspace -and $sync.runspace.RunspacePoolStateInfo.State -eq [System.Management.Automation.Runspaces.RunspacePoolState]::Opened) {
|
|
return $sync.runspace
|
|
}
|
|
|
|
if ($sync.runspace) {
|
|
Close-WinUtilRunspacePool
|
|
}
|
|
|
|
# Set the maximum number of threads for the RunspacePool to the number of threads on the machine.
|
|
$maxthreads = [Math]::Max([int]$env:NUMBER_OF_PROCESSORS, 1)
|
|
|
|
# Create a new session state for parsing variables into our runspace.
|
|
$hashVars = New-Object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'sync', $sync, $null
|
|
$offlineVar = New-Object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'PARAM_OFFLINE', $PARAM_OFFLINE, $null
|
|
$initialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
|
|
|
|
$initialSessionState.Variables.Add($hashVars)
|
|
$initialSessionState.Variables.Add($offlineVar)
|
|
|
|
# Get every WinUtil/WPF function and add it to the session state.
|
|
$functions = Get-ChildItem function:\ | Where-Object { $_.Name -imatch 'winutil|WPF' }
|
|
foreach ($function in $functions) {
|
|
$functionDefinition = Get-Content function:\$($function.Name)
|
|
$functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $function.Name, $functionDefinition
|
|
$initialSessionState.Commands.Add($functionEntry)
|
|
}
|
|
|
|
$sync.runspace = [runspacefactory]::CreateRunspacePool(
|
|
1, # Minimum thread count
|
|
$maxthreads, # Maximum thread count
|
|
$initialSessionState, # Initial session state
|
|
$Host # Machine to create runspaces on
|
|
)
|
|
|
|
$sync.runspace.Open()
|
|
Write-WinUtilPerformanceCheckpoint -Name "Runspace pool initialized"
|
|
return $sync.runspace
|
|
}
|