If your Windows Terminal feels sluggish during startup, it’s likely due to synchronous initialization of heavy CLI tools. By shifting these to a Lazy Loading strategy, you can drop your profile load time from 140ms to under 20ms.
# 1. BusyBox (Linux Commands) - Fast & Direct
if (Get-Command busybox -ErrorAction SilentlyContinue) {
# Remove default PowerShell 'ls' alias to use BusyBox version
if (Get-Alias ls -ErrorAction SilentlyContinue) { Remove-Item Alias:ls -Force }
# Map Linux functions (2>$null silences Windows-specific 'nul' path errors)
function ls { busybox ls --color=auto $args 2>$null }
function ll { busybox ls -lh $args 2>$null }
function grep { busybox grep --color=auto $args }
}
# 2. Starship Prompt - Lazy Loaded
# This defers execution until the terminal window is already visible.
$staticPrompt = {
# Initialize Starship only when the first prompt is rendered
Invoke-Expression (&starship init powershell)
# Immediately execute the newly generated Starship prompt
& $function:prompt
}
Set-Item -Path function:prompt -Value $staticPrompt
Performance Comparison
The following data is measured using Measure-Command { . $PROFILE } on a standard development machine.
| Metric | Sync Init (Standard) | Lazy Load (Optimized) | Improvement |
| Profile Load Time | 140.47 ms | 16.49 ms | ~8.5x Faster |
| Visual Latency | Noticeable stutter | Instant window popup | Significant |
| Process Overhead | High (Block on startup) | Zero (Deferred to first idle) | – |
Why this works
- Eliminating Executable Calls: Directly defining
functionin the profile is micro-seconds faster than searching for.exefiles every time. - Deferring I/O:
starship initgenerates thousands of lines of script. Moving this out of the synchronous boot sequence allows the terminal UI to render before the “heavy lifting” starts.