You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf: Use Polars Series for merchant filtering in edit modal
**Performance Optimization:**
Store all_merchants as Polars Series instead of Python list to enable
fast vectorized filtering operations.
**Before (slow with thousands of merchants):**
- Store as Python list
- Filter: `[m for m in merchants if query in m.lower()]` - Python loop
- Sort/dedupe: `sorted(set(matches))[:20]` - Python operations
**After (fast with thousands of merchants):**
- Store as Polars Series in __init__
- Filter: `series.filter(series.str.to_lowercase().str.contains(query))` - vectorized
- Sort/dedupe/limit: `filtered.unique().sort().head(20)` - Polars operations
- Only convert to Python list at the end for UI rendering
**Implementation Details:**
- Added `import polars as pl` at top of file (no inline imports)
- Type annotation: `self.all_merchants: pl.Series | None`
- Variable name unchanged (self.all_merchants) - type annotation makes it clear
- Updated all None checks to use `is not None` (not truthiness)
- Single conversion from list to Series in __init__ (not on every keystroke)
**Performance Benefits:**
- Vectorized string operations (much faster than Python loops)
- No repeated Series creation (convert once in __init__)
- Polars handles deduplication and sorting natively
- Especially noticeable with 1000+ unique merchants
**Testing:**
- All 765 tests pass
- test_editing.py: 100% coverage
- No behavior changes - purely performance optimization
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
0 commit comments