ML-169.2: performed performance audit

This commit is contained in:
Claudio Ortolina
2026-05-19 08:45:58 +01:00
parent faafe8792f
commit 8de5d88c14
2 changed files with 300 additions and 10 deletions
@@ -1,10 +1,10 @@
---
id: ML-169.2
title: "Phase 4: Performance low-hanging fruit audit"
status: To Do
status: Done
assignee: []
created_date: "2026-05-08 08:59"
updated_date: "2026-05-11 06:46"
updated_date: "2026-05-19 07:44"
labels:
- audit
- ready
@@ -14,6 +14,10 @@ references:
- lib/music_library_web/live_helpers/index_actions.ex
- lib/music_library_web/live_helpers/record_actions.ex
- .agents/skills/query-reporter/SKILL.md
- /tmp/queries-ml-audit.sql
- >-
backlog/documents/doc-27 -
Phase-4-Performance-Audit-Low-Hanging-Fruit-Findings.md
parent_task_id: ML-169
priority: medium
---
@@ -39,12 +43,36 @@ Key pre-flagged areas:
<!-- AC:BEGIN -->
- [ ] #1 SQL traces captured via QueryReporter for /collection, /collection/:id, /stats, /artists/:id
- [ ] #2 Stream reset audit complete: every stream(:name, data, reset: true) call site evaluated for incremental-update alternatives
- [ ] #3 Display toggle (grid/list) evaluated: confirmed whether CSS-only toggle can replace full DB reload
- [ ] #4 StatsLive.Index mount blocking work quantified: 5 queries identified, assign_async feasibility assessed
- [ ] #5 Search input debounce verified: phx-debounce attribute presence checked on all search forms
- [ ] #6 Optimistic UI opportunities identified for delete, form save, toggle operations
- [ ] #7 N+1 audit complete: handle_params, stream rendering, and LiveComponent Repo calls checked
- [ ] #8 Findings report written as a Backlog.md document with file:line references, severity ratings, and fix recommendations
- [x] #1 SQL traces captured via QueryReporter for /collection, /collection/:id, /stats, /artists/:id
- [x] #2 Stream reset audit complete: every stream(:name, data, reset: true) call site evaluated for incremental-update alternatives
- [x] #3 Display toggle (grid/list) evaluated: confirmed whether CSS-only toggle can replace full DB reload
- [x] #4 StatsLive.Index mount blocking work quantified: 5 queries identified, assign_async feasibility assessed
- [x] #5 Search input debounce verified: phx-debounce attribute presence checked on all search forms
- [x] #6 Optimistic UI opportunities identified for delete, form save, toggle operations
- [x] #7 N+1 audit complete: handle_params, stream rendering, and LiveComponent Repo calls checked
- [x] #8 Findings report written as a Backlog.md document with file:line references, severity ratings, and fix recommendations
<!-- AC:END -->
## Final Summary
<!-- SECTION:FINAL_SUMMARY:BEGIN -->
## Audit Complete: 9 findings across 4 severity levels
**SQL traces captured** via QueryReporter at `/tmp/queries-ml-audit.sql` for all 4 key pages (StatsLive, CollectionLive.Index, CollectionLive.Show, ArtistLive.Show).
### Key findings:
**HIGH severity (3)**:
1. **Display toggle triggers full DB reload** — grid/list toggle in `handle_set_display` re-executes FTS search when CSS-only toggle suffices. Fix: remove `load_and_assign_records` call.
2. **StatsLive.Index mount: 10 sync queries** — home page TTFB blocked by 10 sequential queries. `assign_async` already used elsewhere on the same page — extend it to cover heavy queries.
3. **Scrobble updates trigger full stream reset** — every 5-minute cron batch causes `reset: true` on all connected clients for both StatsLive and ScrobbledTracksLive.
**MEDIUM severity (4)**: 4. **Redundant stream_insert + immediate full reload** in ScrobbleRulesLive and OnlineStoreTemplateLive — `stream_insert` is immediately nullified by `load_and_assign_*`. 5. **Full resets on pagination**`reset: true` on page changes when append could suffice. 6. **Missing optimistic UI** for delete operations — DB waits block UI. 7. **Correlated subqueries** in `ListeningStats.tracks_with_record_info_query` — 3 subqueries per row × 100 tracks.
**PASS (2)**: 8. All search inputs have `phx-debounce` set. 9. No direct N+1 issues found in LiveView/LiveComponent layer (no direct Repo calls).
Full report: `docs/backlog/documents/doc-27` — includes file:line references, SQL traces, and fix recommendations for each finding.
<!-- SECTION:FINAL_SUMMARY:END -->