elixir-phoenix-assigns-audit
Audit LiveView assigns for memory bloat, dead assigns, and stream candidates.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Audit LiveView assigns for memory bloat, dead assigns, and stream candidates.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Recommend the right `$elixir-phoenix-*` skill for the current task.
Elixir/Phoenix: Review lifecycle, state-machine, Oban, persistence, pause/resume, retry, and restart-sensitive changes before commit, push, or PR. Use for concurrency-sensitive runtime work to produce explicit blocking vs optional findings, require durability checks, and verify smoke plus restart resilience when applicable.
Capture a solved Phoenix problem as a reusable solution doc.
Audit project health across architecture, security, performance, tests, and deps.
Analyze Phoenix context boundaries and coupling with `mix xref`.
Brainstorm Phoenix features, tradeoffs, and requirements before planning.
| name | elixir-phoenix-assigns-audit |
| description | Audit LiveView assigns for memory bloat, dead assigns, and stream candidates. |
| metadata | {"short-description":"Audit LiveView assigns for memory bloat"} |
Analyze LiveView socket assigns for memory efficiency, clarity, and best practices.
Use rg to find all assign( and assign_new( calls in the target LiveView file.
Use rg to find large data patterns: lists stored in assigns (assign.*\[\], assign.*Repo\.all) and full schema storage (assign.*Repo\.get) in the target file.
| Pattern | Problem | Solution |
|---|---|---|
assign(:items, Repo.all(...)) | Unbounded list | Use stream/3 |
assign(:user, Repo.get!(...)) | Full schema | Select only needed fields |
assign(:file_data, binary) | Large binary | Store reference, not data |
| Nested preloads | Excessive data | Preload only what's rendered |
Should use temporary_assigns:
def mount(_params, _session, socket) do
{:ok, socket, temporary_assigns: [flash_message: nil]}
end
Search for assigns defined but never used in templates:
Use rg to extract all assign names (assign\(:(\w+)) from the LiveView file, then use rg to find all @\w+ references in the corresponding .heex template. Compare to find unused assigns.
# BAD: @items might not exist
def render(assigns) do
~H"<%= for item <- @items do %>"
end
# GOOD: Initialize in mount
def mount(_params, _session, socket) do
{:ok, assign(socket, items: [])}
end
For each assign, estimate memory footprint:
| Data Type | Approx Size | Concern Level |
|---|---|---|
| Integer | 8 bytes | Low |
| String (100 chars) | ~200 bytes | Low |
| List of 100 maps | ~10-50 KB | Medium |
| List of 1000 items | ~100-500 KB | High |
| Binary (image) | Varies | Critical |
| Full Ecto schema | ~1-5 KB each | Medium |
Run ``elixir-phoenix-assigns-audit path/to/live_view.ex to generate an assigns inventory with memory estimates and optimization recommendations.