Supercharge PowerShell Startup: Lazy Load

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.

MetricSync Init (Standard)Lazy Load (Optimized)Improvement
Profile Load Time140.47 ms16.49 ms~8.5x Faster
Visual LatencyNoticeable stutterInstant window popupSignificant
Process OverheadHigh (Block on startup)Zero (Deferred to first idle)

Why this works

  • Eliminating Executable Calls: Directly defining function in the profile is micro-seconds faster than searching for .exe files every time.
  • Deferring I/O: starship init generates thousands of lines of script. Moving this out of the synchronous boot sequence allows the terminal UI to render before the “heavy lifting” starts.

No Comments

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
Previous