- Analyze: We need to find ONE performance optimization in the codebase that's small (<50 lines), effective, safe, and doesn't affect architecture or dependencies. We've investigated several things:
_probe_servicesinsrc/bantz/interface/live_ui.py: It's already usingasyncio.gatherfor checking services concurrently.sqlite_storeand other db classes doingSELECT COUNT(*)where they shouldn't: They seem to be counting actual rows needed for stats (not just existence checks whereLIMIT 1is better).src/bantz/vision/spatial_cache.py: LRU eviction usesSELECT COUNT(*), which could be slow.src/bantz/agent/app_detector.py_proc_running_apps: The code was updated to useos.scandirinstead ofos.listdir, which is already good.src/bantz/tools/news.py: Contains a classic N+1 API call problem in_fetch_hn(Hacker News) where it loops over IDs and makes sequentialawait client.get(...)calls.
-
The Discovery in
news.py: Insrc/bantz/tools/news.py, around line 148:for story_id in ids: item_resp = await client.get( f"https://hacker-news.firebaseio.com/v0/item/{story_id}.json", timeout=TIMEOUT, )
This does sequential fetches for Hacker News items. We created a test script that proves doing these concurrently using
asyncio.gathercuts fetch time significantly. -
The Fix: Modify
_fetch_hninsrc/bantz/tools/news.pyto fetch stories concurrently usingasyncio.gather. We will keep it clean and robust, handling exceptions per request (viareturn_exceptions=Trueor a try-except block inside the helper). This solves an N+1 API call bottleneck, fitting the criteria perfectly. -
Plan:
- Step 1: Modify
src/bantz/tools/news.pyto useasyncio.gatherto fetch Hacker News items concurrently, rather than sequentially. Add a comment explaining the performance optimization. - Step 2: Complete pre-commit steps to ensure proper testing, verification, review, and reflection are done. This includes running the full test suite and linting.
- Step 3: Commit and submit the code as a PR with the required
⚡ Bolt: [performance improvement]title and description format.
- Step 1: Modify