Skip to content

Instantly share code, notes, and snippets.

@cassidoo
Created June 2, 2026 03:47
Show Gist options
  • Select an option

  • Save cassidoo/8ccbe8902f5d637c62d36b77aa34c4ae to your computer and use it in GitHub Desktop.

Select an option

Save cassidoo/8ccbe8902f5d637c62d36b77aa34c4ae to your computer and use it in GitHub Desktop.
Diagnostic script for slow npm run rayfin:dev on Windows

Diagnose Slow npm run rayfin:dev on Windows

You are diagnosing why npm run rayfin:dev (which runs rayfin dev) is extremely slow on this Windows machine. On another machine, the following two fixes brought startup from ~150s down to ~4s:

  1. Windows Defender path exclusions — Defender real-time scanning of thousands of .js files in node_modules causes 100+ second delays on cold starts
  2. Rayfin telemetry opt-outRAYFIN_TELEMETRY_OPTOUT=1 as a persistent user env var, which prevents loading ~12,000 OpenTelemetry dependency files

Step 1: Run this diagnostic script

Run the following in PowerShell and share the full output:

Write-Host "=== DIAGNOSTIC REPORT ==="
Write-Host ""

# 1. Check telemetry opt-out
Write-Host "--- Telemetry Opt-Out ---"
Write-Host "Current session: RAYFIN_TELEMETRY_OPTOUT = $env:RAYFIN_TELEMETRY_OPTOUT"
Write-Host "Persisted (User): $([System.Environment]::GetEnvironmentVariable('RAYFIN_TELEMETRY_OPTOUT', 'User'))"
Write-Host ""

# 2. Check Defender status
Write-Host "--- Windows Defender ---"
Get-MpComputerStatus | Select-Object RealTimeProtectionEnabled, OnAccessProtectionEnabled | Format-List
Write-Host ""

# 3. Check Defender exclusions (requires admin — will show N/A if not admin)
Write-Host "--- Defender Exclusions ---"
try {
    $excl = (Get-MpPreference).ExclusionPath
    if ($excl) { $excl | ForEach-Object { Write-Host "  $_" } }
    else { Write-Host "  (none set)" }
} catch { Write-Host "  (requires admin to view)" }
Write-Host ""

# 4. Find Node/npm/rayfin locations
Write-Host "--- Tool Locations ---"
Write-Host "node: $((Get-Command node -ErrorAction SilentlyContinue).Source)"
Write-Host "npm:  $((Get-Command npm -ErrorAction SilentlyContinue).Source)"
Write-Host "rayfin: $((Get-Command rayfin -ErrorAction SilentlyContinue).Source)"
Write-Host "node version: $(node --version 2>&1)"
Write-Host "npm version: $(npm --version 2>&1)"
Write-Host ""

# 5. Count JS files rayfin must load (shows Defender scan scope)
Write-Host "--- Rayfin Dependency Size ---"
$rayfinParent = Split-Path (Get-Command rayfin -ErrorAction SilentlyContinue).Source
$rayfinModules = Join-Path $rayfinParent "node_modules\@microsoft\rayfin-cli\node_modules"
if (Test-Path $rayfinModules) {
    $count = (Get-ChildItem $rayfinModules -Recurse -Filter "*.js" -File).Count
    Write-Host "  JS files in rayfin deps: $count"
} else {
    Write-Host "  Could not find rayfin node_modules at: $rayfinModules"
}
Write-Host ""

# 6. Check project node_modules
Write-Host "--- Project node_modules ---"
Write-Host "  Exists: $(Test-Path node_modules)"
if (Test-Path node_modules) {
    $projCount = (Get-ChildItem node_modules -Recurse -Filter "*.js" -File).Count
    Write-Host "  JS files: $projCount"
}
Write-Host ""

# 7. Timing tests
Write-Host "--- Timing Tests ---"

Write-Host "node -e (baseline):"
$t0 = Measure-Command { node -e "console.log('ok')" 2>&1 }
Write-Host "  $($t0.TotalSeconds)s"

Write-Host "rayfin --version (run 1 - cold):"
$t1 = Measure-Command { rayfin --version 2>&1 }
Write-Host "  $($t1.TotalSeconds)s"

Write-Host "rayfin --version (run 2 - warm):"
$t2 = Measure-Command { rayfin --version 2>&1 }
Write-Host "  $($t2.TotalSeconds)s"

$variance = [math]::Round([math]::Abs($t1.TotalSeconds - $t2.TotalSeconds), 1)
Write-Host ""
Write-Host "Cold/warm variance: ${variance}s"
if ($variance -gt 10) {
    Write-Host "  WARNING: High variance suggests Defender is still scanning these files."
    Write-Host "  Defender exclusions are likely missing or not covering the right paths."
}
Write-Host ""

# 8. Check if both runs are still slow (>10s)
if ($t2.TotalSeconds -gt 10) {
    Write-Host "  WARNING: Even warm run is slow ($($t2.TotalSeconds)s)."
    Write-Host "  Possible causes: telemetry still on, corporate EDR, or slow network for telemetry flush."
}

Write-Host ""
Write-Host "=== END DIAGNOSTIC ==="

Step 2: Interpret the results

If RAYFIN_TELEMETRY_OPTOUT is not 1:

[System.Environment]::SetEnvironmentVariable("RAYFIN_TELEMETRY_OPTOUT", "1", "User")
$env:RAYFIN_TELEMETRY_OPTOUT = "1"

Then restart the terminal and re-run diagnostics.

If Defender exclusions are missing or don't cover the right paths:

Run in an admin PowerShell, using the actual paths from the "Tool Locations" section:

# Replace these paths with the actual ones from the diagnostic output
Add-MpPreference -ExclusionPath "C:\path\to\nodejs\node_modules"
Add-MpPreference -ExclusionPath "$env:LOCALAPPDATA\npm-cache"
Add-MpPreference -ExclusionPath "C:\path\to\your\project\repos"

Important: The exclusion paths must match where node, rayfin, and node_modules actually live on THIS machine. Use the paths from the diagnostic output — they may differ from the other machine.

If cold/warm variance is high (>10s) AFTER adding exclusions:

  • The exclusion paths may not cover all directories being scanned
  • There may be a corporate EDR (endpoint detection) tool running alongside Defender
  • Check: Get-Process | Where-Object { $_.CPU -gt 10 } | Sort-Object CPU -Descending | Select-Object -First 10 Name, CPU, Id
  • Look for EDR processes: CrowdStrike (csfalconservice), Carbon Black (cb), SentinelOne (SentinelAgent), etc.

If BOTH runs are slow (>10s) even with telemetry off:

  • Rayfin CLI itself takes 3-5s baseline (normal)
  • Check for network delays: Measure-Command { [System.Net.Dns]::GetHostAddresses("registry.npmjs.org") } | Select-Object TotalSeconds
  • Check for corporate proxy: $env:HTTP_PROXY; $env:HTTPS_PROXY
  • Check Docker status: docker info 2>&1 | Select-String "proxy|Server Version"

If project node_modules doesn't exist:

npm install

This is required for npm run scripts to resolve local binaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment