|
| 1 | +# Performance Improvement Recommendations for vim-fall |
| 2 | + |
| 3 | +After analyzing the codebase, here are key performance improvement |
| 4 | +opportunities: |
| 5 | + |
| 6 | +## ✅ Implemented Improvements |
| 7 | + |
| 8 | +### 1. Optimized Event Queue Processing |
| 9 | + |
| 10 | +- **Change**: Replaced `forEach` with `for` loop and added early return for |
| 11 | + empty queue |
| 12 | +- **Impact**: Reduced overhead for event processing, especially with many events |
| 13 | +- **Files**: `event.ts` |
| 14 | +- **Tests**: Enhanced `event_test.ts` with performance and edge case tests |
| 15 | + |
| 16 | +### 2. Cached Byte Length Calculations |
| 17 | + |
| 18 | +- **Change**: Added caching for prefix/suffix byte lengths in input component |
| 19 | +- **Impact**: Avoids repeated UTF-8 encoding operations during rendering |
| 20 | +- **Files**: `component/input.ts` |
| 21 | +- **Tests**: Existing tests in `component/input_test.ts` ensure correctness |
| 22 | + |
| 23 | +### 3. Lazy Preview Loading with Debounce |
| 24 | + |
| 25 | +- **Change**: Added 150ms debounce to preview updates during cursor movement |
| 26 | +- **Impact**: Prevents unnecessary preview processing during rapid navigation |
| 27 | +- **Files**: `picker.ts`, `lib/debounce.ts` (new) |
| 28 | +- **Tests**: Created comprehensive tests in `lib/debounce_test.ts` |
| 29 | + |
| 30 | +### 4. Copy-on-Write for Processor Items |
| 31 | + |
| 32 | +- **Change**: Implemented deep cloning of items in sort and render processors |
| 33 | +- **Impact**: Eliminated need to restart from match processor when switching sorters/renderers |
| 34 | +- **Files**: `processor/sort.ts`, `processor/render.ts`, `picker.ts`, `lib/item_clone.ts` (new) |
| 35 | +- **Tests**: Created tests in `lib/item_clone_test.ts`, updated `processor/sort_test.ts` |
| 36 | + |
| 37 | +## 📋 Remaining Opportunities |
| 38 | + |
| 39 | +## 1. Reduce Component Re-renders |
| 40 | + |
| 41 | +Components check multiple modified flags on every scheduler tick (10ms). The |
| 42 | +input component (input.ts:232-247) renders even when only spinner updates: |
| 43 | + |
| 44 | +```typescript |
| 45 | +get #isSpinnerUpdated(): boolean { |
| 46 | + return (this.collecting || this.processing) && !this.#spinner.locked; |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +**Solution**: Implement dirty checking with granular update flags and batch DOM |
| 51 | +updates. |
| 52 | + |
| 53 | +## 2. Improve Memory Management |
| 54 | + |
| 55 | +UniqueOrderedList (unique_ordered_list.ts) maintains both Set and Array: |
| 56 | + |
| 57 | +```typescript |
| 58 | +#seen: Set<unknown> = new Set(); |
| 59 | +#items: T[]; |
| 60 | +``` |
| 61 | + |
| 62 | +**Solution**: For large datasets, consider a single Map<unknown, T> with |
| 63 | +insertion order preservation. |
| 64 | + |
| 65 | +## 3. Batch Async Operations |
| 66 | + |
| 67 | +Multiple processors can trigger simultaneously, causing cascading updates: |
| 68 | + |
| 69 | +```typescript |
| 70 | +// collect-processor-updated triggers match |
| 71 | +// match-processor-updated triggers sort |
| 72 | +// sort-processor-succeeded triggers render |
| 73 | +``` |
| 74 | + |
| 75 | +**Solution**: Implement update batching with a priority queue to coalesce rapid |
| 76 | +changes. |
| 77 | + |
| 78 | +## 4. Optimize Scheduler Interval |
| 79 | + |
| 80 | +Default 10ms scheduler interval may be too aggressive for some operations: |
| 81 | + |
| 82 | +```typescript |
| 83 | +const SCHEDULER_INTERVAL = 10; |
| 84 | +``` |
| 85 | + |
| 86 | +**Solution**: Make scheduler adaptive based on workload - increase interval when |
| 87 | +idle, decrease during active input. |
| 88 | + |
| 89 | +## 5. Virtual Scrolling Enhancement |
| 90 | + |
| 91 | +Current implementation slices arrays on every render: |
| 92 | + |
| 93 | +```typescript |
| 94 | +const displayItems = items |
| 95 | + .slice(this.offset, this.offset + this.height); |
| 96 | +``` |
| 97 | + |
| 98 | +**Solution**: Implement a viewport buffer that reuses item objects when |
| 99 | +scrolling incrementally. |
| 100 | + |
| 101 | +## 6. Worker Thread Processing |
| 102 | + |
| 103 | +For CPU-intensive operations like matching/sorting large datasets: |
| 104 | + |
| 105 | +**Solution**: Move matcher/sorter processing to Web Workers to keep UI thread |
| 106 | +responsive. |
| 107 | + |
| 108 | +## Implementation Priority |
| 109 | + |
| 110 | +1. **High Impact, Low Effort**: |
| 111 | + ✅ Lazy preview loading (implemented) |
| 112 | + ✅ String operation caching (implemented) |
| 113 | + ✅ Event queue optimization (implemented) |
| 114 | + ✅ Copy-on-write for processor items (implemented) |
| 115 | + |
| 116 | +2. **High Impact, Medium Effort**: |
| 117 | + - Batch async operations (#3) |
| 118 | + - Component re-render optimization (#1) |
| 119 | + |
| 120 | +3. **High Impact, High Effort**: |
| 121 | + - Worker thread processing (#6) |
| 122 | + - Virtual scrolling enhancement (#5) |
| 123 | + |
| 124 | +4. **Medium Impact**: |
| 125 | + - Memory management improvements (#2) |
| 126 | + - Adaptive scheduler (#4) |
| 127 | + |
| 128 | +These optimizations would significantly improve latency, especially for large |
| 129 | +datasets and rapid user interactions. |
0 commit comments