Commit 7c382f3
perf: Use Polars operations in get_all_merchants_for_autocomplete
**Optimization:**
Replaced Python set operations with Polars vectorized operations in
get_all_merchants_for_autocomplete().
**Before (slow with thousands of merchants):**
```python
merchants_set = set(self.all_merchants)
current_merchants = self.df["merchant"].unique().to_list()
merchants_set.update(current_merchants)
return sorted(merchants_set)
```
- Two conversions to Python (to_list, set)
- Python set operations
- Python sorted()
**After (fast):**
```python
cached_series = pl.Series("merchant", self.all_merchants)
current_series = self.df["merchant"].unique()
all_merchants = pl.concat([cached_series, current_series]).unique().sort()
return all_merchants.to_list()
```
- One conversion to Polars Series (cached merchants)
- Polars concat, unique, sort (vectorized)
- Single to_list() at the end
**Performance Impact:**
This method is called every time the edit merchant modal is opened, so
optimization here directly improves UI responsiveness.
With 1000+ merchants:
- Polars concat: O(n) in Rust
- Polars unique: Hash-based, optimized
- Polars sort: Optimized sorting algorithm
- Much faster than Python set operations
**Other Findings:**
Reviewed other sorted/set operations in codebase:
- save_merchants_cache: sorted(set()) is appropriate (preparing for JSON)
- SelectCategoryScreen: sorting dict items, not DataFrame data
- Demo backend: small data, not performance critical
- duplicate_detector: small groups, not critical
- categories.py: small lists, not critical
**Testing:**
- All 765 tests pass
- No behavior changes - purely performance optimization
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 9fda8b0 commit 7c382f3
1 file changed
+10
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
281 | | - | |
282 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
283 | 284 | | |
284 | | - | |
| 285 | + | |
285 | 286 | | |
286 | | - | |
287 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
288 | 292 | | |
289 | | - | |
| 293 | + | |
290 | 294 | | |
291 | 295 | | |
292 | 296 | | |
| |||
0 commit comments