LiveView Assigns Audit skill

Inspect LiveView socket assigns for memory bloat — missing temporary_assigns, unused assigns, unbounded lists needing streams, memory estimates.

by oliver-kriska·MIT license·★ 560 Stars on the repo·GitHub ↗

Use now

Files of LiveView Assigns Audit

oliver-kriska/main1 file shown
SKILL.md
Show the full text92 lines

LiveView Assigns Audit

Analyze LiveView socket assigns for memory efficiency, clarity, and best practices.

Iron Laws - Never Violate These

  1. Use streams for lists > 100 items - Never store large lists directly in assigns
  2. Use temporary_assigns for transient data - Flash messages, temp errors, notifications
  3. Preload only needed fields - Don't store full Ecto schemas when only needing subset
  4. Initialize all assigns in mount - Never access assigns that might not exist
  5. NEVER modify assigns or code during audit — this is a read-only diagnostic; report findings only

Quick Audit Commands

Extract All Assigns

Use Grep to find all assign( and assign_new( calls in the target LiveView file.

Find Large Data Patterns

Use Grep to find large data patterns: lists stored in assigns (assign.*\[\], assign.*Repo\.all) and full schema storage (assign.*Repo\.get) in the target file.

Audit Checklist

1. Memory Issues
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
2. Missing temporary_assigns

Should use temporary_assigns:

  • Flash messages
  • Form errors after submission
  • One-time notifications
  • Upload progress
def mount(_params, _session, socket) do
  {:ok, socket, temporary_assigns: [flash_message: nil]}
end
3. Unused Assigns

Search for assigns defined but never used in templates:

Use Grep to extract all assign names (assign\(:(\w+)) from the LiveView file, then use Grep to find all @\w+ references in the corresponding .heex template. Compare to find unused assigns.

4. Missing Initialization
# 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

Memory Estimation

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

Usage

Run /lv:assigns path/to/live_view.ex to generate an assigns inventory with memory estimates and optimization recommendations.

1---
2name: assigns-audit
3description: "Inspect LiveView socket assigns for memory bloat — missing temporary_assigns, unused assigns, unbounded lists needing streams, memory estimates. Use when LiveView memory grows or you need to add temporary_assigns."
4effort: medium
5argument-hint: path/to/live_view.ex
6---
7 
8# LiveView Assigns Audit
9 
10Analyze LiveView socket assigns for memory efficiency, clarity, and best practices.
11 
12## Iron Laws - Never Violate These
13 
141. **Use streams for lists > 100 items** - Never store large lists directly in assigns
152. **Use temporary_assigns for transient data** - Flash messages, temp errors, notifications
163. **Preload only needed fields** - Don't store full Ecto schemas when only needing subset
174. **Initialize all assigns in mount** - Never access assigns that might not exist
185. **NEVER modify assigns or code during audit** — this is a read-only diagnostic; report findings only
19 
20## Quick Audit Commands
21 
22### Extract All Assigns
23 
24Use Grep to find all `assign(` and `assign_new(` calls in the target LiveView file.
25 
26### Find Large Data Patterns
27 
28Use Grep to find large data patterns: lists stored in assigns (`assign.*\[\]`, `assign.*Repo\.all`) and full schema storage (`assign.*Repo\.get`) in the target file.
29 
30## Audit Checklist
31 
32### 1. Memory Issues
33 
34| Pattern | Problem | Solution |
35|---------|---------|----------|
36| `assign(:items, Repo.all(...))` | Unbounded list | Use `stream/3` |
37| `assign(:user, Repo.get!(...))` | Full schema | Select only needed fields |
38| `assign(:file_data, binary)` | Large binary | Store reference, not data |
39| Nested preloads | Excessive data | Preload only what's rendered |
40 
41### 2. Missing temporary_assigns
42 
43Should use `temporary_assigns`:
44 
45- Flash messages
46- Form errors after submission
47- One-time notifications
48- Upload progress
49 
50```elixir
51def mount(_params, _session, socket) do
52 {:ok, socket, temporary_assigns: [flash_message: nil]}
53end
54```
55 
56### 3. Unused Assigns
57 
58Search for assigns defined but never used in templates:
59 
60Use Grep to extract all assign names (`assign\(:(\w+)`) from the LiveView file, then use Grep to find all `@\w+` references in the corresponding `.heex` template. Compare to find unused assigns.
61 
62### 4. Missing Initialization
63 
64```elixir
65# BAD: @items might not exist
66def render(assigns) do
67 ~H"<%= for item <- @items do %>"
68end
69 
70# GOOD: Initialize in mount
71def mount(_params, _session, socket) do
72 {:ok, assign(socket, items: [])}
73end
74```
75 
76## Memory Estimation
77 
78For each assign, estimate memory footprint:
79 
80| Data Type | Approx Size | Concern Level |
81|-----------|-------------|---------------|
82| Integer | 8 bytes | Low |
83| String (100 chars) | ~200 bytes | Low |
84| List of 100 maps | ~10-50 KB | Medium |
85| List of 1000 items | ~100-500 KB | High |
86| Binary (image) | Varies | Critical |
87| Full Ecto schema | ~1-5 KB each | Medium |
88 
89## Usage
90 
91Run `/lv:assigns path/to/live_view.ex` to generate an assigns inventory with memory estimates and optimization recommendations.
92 

Discussion

Alternatives

Wiki Export — Knowledge Graph ExportExport the Obsidian wiki's knowledge graph to structured formats for use in external tools. Use this skill when the user says "export wiki", "export graph", "export to JSON", "export to Gephi", export to Neo4j", "export to Postgres", "export to SQL", "graphml", "visualize wiki", knowledge graph export", "export to OKF", "OKF bundle", "open knowledge format", export as markdown bundle", or wants to use their wiki data in another tool. Outputs graph.json, graph.graphml, cypher.txt (Neo4j), postgres.sql (Postgres), and graph.html (interactive browser visualization) into a wiki-export/ directory at the vault root, plus an optional OKF (Open Knowledge Format) markdown bundle under wiki-export/okf/.Business & ops · MITWiki Import — Reconstruct Pages from an ExportImport a wiki knowledge graph into the current vault — either from a graph.json export file (stubs) or from an OKF (Open Knowledge Format) markdown bundle (full page bodies). Use this skill when the user says "import wiki", "import from export", "load graph.json", import vault", "import OKF bundle", "import OKF", "load OKF", "import markdown bundle", /wiki-import", or wants to transfer pages from one vault to another using the output of wiki-export.Business & ops · MIT/recall: session memory engineFind prior Claude Code and Codex sessions with an indexed local search engine, then continue the work, repeat it with fresh inputs, or distill it into a skill. Runs from Claude Code, Codex, or pi; the current index covers Claude Code and Codex transcripts. Use when the user names Recall, says "find that conversation where…", "what did we do last time about…", "continue what we did yesterday on X", "what did codex do on this branch", "turn what we did about Y into a skill", or "remember when you…". Not for searching code (use grep on the repo) or for facts already in MEMORY.md.Business & ops · MITKnowledge Graph Memory ServerA basic implementation of persistent memory using a local knowledge graph. This lets Claude remember information about the user across…Coding · MIT