|
1 | | -# File Detection Performance Comparison |
| 1 | +# Launchpad Performance Benchmarks |
2 | 2 |
|
3 | | -This benchmark compares the performance of different approaches for detecting project configuration files in directory trees, specifically comparing the current shell-based implementation with custom Bun/TypeScript alternatives. |
| 3 | +This document contains performance benchmarks for Launchpad's caching system and file detection mechanisms. |
4 | 4 |
|
5 | 5 | ## 🎯 Key Findings |
6 | 6 |
|
| 7 | +### Cache Performance |
| 8 | +The enhanced caching system delivers **10,000x - 50,000x performance improvements**: |
| 9 | + |
| 10 | +- **Cache Hit**: Sub-microsecond (<0.001ms) - **99.9%+ faster than disk I/O** |
| 11 | +- **Cache Miss**: Sub-microsecond (<0.001ms) - Instant fallback |
| 12 | +- **Cache Write**: 7.3ms avg (debounced, non-blocking) |
| 13 | + |
| 14 | +### File Detection Performance |
7 | 15 | The Bun-based approaches are **dramatically faster** than the current shell implementation: |
8 | 16 |
|
9 | | -- **Bun Direct (sync)**: **99.2% faster** on average |
10 | | -- **Bun Glob (async)**: **98.9% faster** on average |
| 17 | +- **Bun Direct (sync)**: **99.7% faster** on average |
| 18 | +- **Shell (current)**: 16-105ms depending on depth |
11 | 19 |
|
12 | 20 | ## 📊 Detailed Results |
13 | 21 |
|
14 | | -| Test Scenario | Bun Direct | Bun Glob | Shell (Current) | Speed Improvement | |
15 | | -|---------------|------------|----------|-----------------|-------------------| |
16 | | -| Shallow (3 levels) | 0.12ms | 0.27ms | 24.85ms | **99.5% faster** | |
17 | | -| Medium (7 levels) | 0.31ms | 0.74ms | 49.96ms | **99.4% faster** | |
18 | | -| Deep (15 levels) | 0.72ms | 0.94ms | 89.68ms | **99.2% faster** | |
19 | | -| Very Deep (25 levels) | 1.39ms | 1.53ms | 143.67ms | **99.0% faster** | |
| 22 | +### Cache Performance Benchmark |
| 23 | + |
| 24 | +Run with: `launchpad benchmark:cache --iterations 50000` |
| 25 | + |
| 26 | +```text |
| 27 | +🚀 Cache Performance Benchmark |
| 28 | +
|
| 29 | +Testing in-memory cache lookup performance... |
| 30 | +
|
| 31 | +Cache lookup (hit) : 0.000ms avg (3.8ms total, 50000 iterations) |
| 32 | +Cache lookup (miss) : 0.000ms avg (2.3ms total, 50000 iterations) |
| 33 | +Cache write : 7.251ms avg (36256.5ms total, 5000 iterations) |
| 34 | +
|
| 35 | +📊 Cache Performance Summary: |
| 36 | +────────────────────────────────────────────────── |
| 37 | +Cache Hit: 0.000ms avg (sub-microsecond) |
| 38 | +Cache Miss: 0.000ms avg (sub-microsecond) |
| 39 | +Cache Write: 7.251ms avg (debounced, non-blocking) |
| 40 | +
|
| 41 | +🎯 Target: <0.001ms for cache hits (sub-microsecond) |
| 42 | +✅ Status: PASSED |
| 43 | +``` |
| 44 | + |
| 45 | +**Key Metrics:** |
| 46 | + |
| 47 | +- **Cache Hit**: Sub-microsecond (0.000ms) - **99.9%+ faster than disk I/O** |
| 48 | +- **Cache Miss**: Sub-microsecond (0.000ms) - Instant fallback |
| 49 | +- **Cache Write**: 7.3ms avg (debounced, doesn't block shell) |
| 50 | + |
| 51 | +#### Real-World Impact |
| 52 | + |
| 53 | +##### Scenario 1: cd within same project (most common) |
| 54 | + |
| 55 | +- Before: ~10-50ms (directory walk + grep) |
| 56 | +- After: **<0.001ms** (path prefix check, no system calls) |
| 57 | +- **Improvement: 10,000x - 50,000x faster** |
| 58 | + |
| 59 | +##### Scenario 2: cd to cached project |
| 60 | + |
| 61 | +- Before: ~10-50ms (directory walk + grep) |
| 62 | +- After: **<0.001ms** (in-memory hash map lookup) |
| 63 | +- **Improvement: 10,000x - 50,000x faster** |
| 64 | + |
| 65 | +##### Scenario 3: cd to new project (cache miss) |
| 66 | + |
| 67 | +- Before: ~10-50ms (shell-based directory walk) |
| 68 | +- After: ~0.1-0.3ms (Bun direct file detection) |
| 69 | +- **Improvement: 100x - 500x faster** |
| 70 | + |
| 71 | +### File Detection Performance Benchmark |
| 72 | + |
| 73 | +Run with: `launchpad benchmark:file-detection` |
| 74 | + |
| 75 | +```text |
| 76 | +📈 PERFORMANCE SUMMARY |
| 77 | +════════════════════════════════════════════════════════════════════════════════ |
| 78 | +Test Case Bun Direct Shell Improvement |
| 79 | +──────────────────────────────────────────────────────────────────────────────── |
| 80 | +3 levels 0.04ms 16.52ms +99.7% faster |
| 81 | +7 levels 0.08ms 32.47ms +99.8% faster |
| 82 | +15 levels 0.16ms 67.54ms +99.8% faster |
| 83 | +25 levels 0.27ms 104.91ms +99.7% faster |
| 84 | +
|
| 85 | +🎯 RECOMMENDATION: Use Bun Direct approach for significant performance gains |
| 86 | +``` |
| 87 | + |
| 88 | +| Test Scenario | Bun Direct | Shell (Current) | Speed Improvement | |
| 89 | +|---------------|------------|-----------------|-------------------| |
| 90 | +| Shallow (3 levels) | 0.04ms | 16.52ms | **99.7% faster (416x)** | |
| 91 | +| Medium (7 levels) | 0.08ms | 32.47ms | **99.8% faster (406x)** | |
| 92 | +| Deep (15 levels) | 0.16ms | 67.54ms | **99.8% faster (421x)** | |
| 93 | +| Very Deep (25 levels) | 0.27ms | 104.91ms | **99.7% faster (387x)** | |
20 | 94 |
|
21 | 95 | ## 🔍 Analysis |
22 | 96 |
|
@@ -138,21 +212,51 @@ The file detection is used in: |
138 | 212 | 3. **Caching**: Both approaches benefit from the existing caching mechanism |
139 | 213 | 4. **Error Handling**: Ensure graceful fallback between approaches |
140 | 214 |
|
141 | | -## 🧪 Running the Benchmark |
| 215 | +## 🧪 Running the Benchmarks |
| 216 | + |
| 217 | +### Cache Performance Benchmark |
| 218 | + |
| 219 | +```bash |
| 220 | +# Default (10,000 iterations) |
| 221 | +launchpad benchmark:cache |
| 222 | + |
| 223 | +# High precision (50,000 iterations) |
| 224 | +launchpad benchmark:cache --iterations 50000 |
| 225 | + |
| 226 | +# JSON output |
| 227 | +launchpad benchmark:cache --json |
| 228 | +``` |
| 229 | + |
| 230 | +### File Detection Performance Benchmark |
142 | 231 |
|
143 | 232 | ```bash |
144 | | -cd packages/launchpad/benchmark |
145 | | -bun install |
146 | | -bun run file-detection-comparison.ts |
| 233 | +# Default depths (3, 7, 15, 25) |
| 234 | +launchpad benchmark:file-detection |
| 235 | + |
| 236 | +# Custom depths |
| 237 | +launchpad benchmark:file-detection --depths 5,10,20 |
| 238 | + |
| 239 | +# JSON output |
| 240 | +launchpad benchmark:file-detection --json |
147 | 241 | ``` |
148 | 242 |
|
149 | | -The benchmark creates temporary directory structures at various depths and measures the time to find project files, providing comprehensive performance data across different scenarios. |
| 243 | +The benchmarks create test scenarios and measure performance across different conditions, providing comprehensive performance data. |
150 | 244 |
|
151 | 245 | ## 📈 Conclusion |
152 | 246 |
|
153 | | -The performance difference is **dramatic and consistent**: |
154 | | -- Bun approaches are **~100x faster** than the shell approach |
| 247 | +The performance improvements are **dramatic and consistent across all areas**: |
| 248 | + |
| 249 | +### Cache System |
| 250 | + |
| 251 | +- **10,000x - 50,000x faster** for cached project lookups |
| 252 | +- Sub-microsecond cache hit times (<0.001ms) |
| 253 | +- Eliminates the primary bottleneck in shell integration |
| 254 | +- Zero disk I/O for subsequent lookups after initial cache load |
| 255 | + |
| 256 | +### File Detection |
| 257 | + |
| 258 | +- Bun approaches are **~400x faster** than the shell approach (99.7%+ improvement) |
155 | 259 | - The performance gap **increases** with directory depth |
156 | 260 | - Implementation complexity is **minimal** for the Bun direct approach |
157 | 261 |
|
158 | | -**Recommendation**: Implement the hybrid approach with Bun Direct as primary and shell as fallback for maximum performance while maintaining compatibility. |
| 262 | +**Recommendation**: The enhanced caching system combined with Bun direct file detection delivers unprecedented performance for shell integration, making directory changes effectively instant in most scenarios. |
0 commit comments