{"id":140,"date":"2026-03-25T20:21:16","date_gmt":"2026-03-25T12:21:16","guid":{"rendered":"https:\/\/dreamhax.cc\/?p=140"},"modified":"2026-03-25T20:21:18","modified_gmt":"2026-03-25T12:21:18","slug":"supercharge-powershell-startup-lazy-load","status":"publish","type":"post","link":"https:\/\/en.dreamhax.cc\/index.php\/2026\/03\/25\/supercharge-powershell-startup-lazy-load\/","title":{"rendered":"Supercharge PowerShell Startup: Lazy Load"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If your Windows Terminal feels sluggish during startup, it&#8217;s likely due to synchronous initialization of heavy CLI tools. By shifting these to a <strong>Lazy Loading<\/strong> strategy, you can drop your profile load time from <strong>140ms<\/strong> to under <strong>20ms<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. BusyBox (Linux Commands) - Fast &amp; Direct\nif (Get-Command busybox -ErrorAction SilentlyContinue) {\n    # Remove default PowerShell 'ls' alias to use BusyBox version\n    if (Get-Alias ls -ErrorAction SilentlyContinue) { Remove-Item Alias:ls -Force }\n    \n    # Map Linux functions (2>$null silences Windows-specific 'nul' path errors)\n    function ls   { busybox ls --color=auto $args 2>$null }\n    function ll   { busybox ls -lh $args 2>$null }\n    function grep { busybox grep --color=auto $args }\n}\n\n# 2. Starship Prompt - Lazy Loaded\n# This defers execution until the terminal window is already visible.\n$staticPrompt = {\n    # Initialize Starship only when the first prompt is rendered\n    Invoke-Expression (&amp;starship init powershell)\n    \n    # Immediately execute the newly generated Starship prompt\n    &amp; $function:prompt\n}\nSet-Item -Path function:prompt -Value $staticPrompt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Performance Comparison<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The following data is measured using <code>Measure-Command { . $PROFILE }<\/code> on a standard development machine.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>Metric<\/td><td>Sync Init (Standard)<\/td><td>Lazy Load (Optimized)<\/td><td>Improvement<\/td><\/tr><tr><td>Profile Load Time<\/td><td>140.47 ms<\/td><td><strong>16.49 ms<\/strong><\/td><td><strong>~8.5x Faster<\/strong><\/td><\/tr><tr><td>Visual Latency<\/td><td>Noticeable stutter<\/td><td>Instant window popup<\/td><td>Significant<\/td><\/tr><tr><td>Process Overhead<\/td><td>High (Block on startup)<\/td><td>Zero (Deferred to first idle)<\/td><td>&#8211;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Why this works<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Eliminating Executable Calls:<\/strong> Directly defining <code>function<\/code> in the profile is micro-seconds faster than searching for <code>.exe<\/code> files every time.<\/li>\n\n\n\n<li><strong>Deferring I\/O:<\/strong> <code>starship init<\/code> generates thousands of lines of script. Moving this out of the synchronous boot sequence allows the terminal UI to render before the &#8220;heavy lifting&#8221; starts.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If your Windows Terminal feels sluggish during startup, it&#8217;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. Performance Comparison The following data is measured using Measure-Command { . $PROFILE } on a standard development [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[107],"tags":[126,10],"class_list":["post-140","post","type-post","status-publish","format-standard","hentry","category-software","tag-powershell","tag-windows"],"_links":{"self":[{"href":"https:\/\/en.dreamhax.cc\/index.php\/wp-json\/wp\/v2\/posts\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/en.dreamhax.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/en.dreamhax.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/en.dreamhax.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/en.dreamhax.cc\/index.php\/wp-json\/wp\/v2\/comments?post=140"}],"version-history":[{"count":1,"href":"https:\/\/en.dreamhax.cc\/index.php\/wp-json\/wp\/v2\/posts\/140\/revisions"}],"predecessor-version":[{"id":141,"href":"https:\/\/en.dreamhax.cc\/index.php\/wp-json\/wp\/v2\/posts\/140\/revisions\/141"}],"wp:attachment":[{"href":"https:\/\/en.dreamhax.cc\/index.php\/wp-json\/wp\/v2\/media?parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/en.dreamhax.cc\/index.php\/wp-json\/wp\/v2\/categories?post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/en.dreamhax.cc\/index.php\/wp-json\/wp\/v2\/tags?post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}