LightningWeb.Live.MemoryDebug (Lightning v2.14.11-pre1)
View SourceMemory debugging utilities for LiveViews to track memory usage and help diagnose OOM issues.
Usage in a LiveView:
import LightningWeb.Live.MemoryDebug
def mount(params, session, socket) do
log_memory("mount start")
# ... your code ...
socket = assign(socket, :data, large_data)
log_memory("after loading large data", socket: socket)
{:ok, socket}
end
Summary
Functions
Compares two memory snapshots and logs the difference.
Logs current memory usage for the calling process and optionally the socket assigns.
Wraps a function call with before/after memory logging.
Measures memory of specific socket assigns.
Gets a memory snapshot as a map (useful for comparing before/after).
Functions
Compares two memory snapshots and logs the difference.
Logs current memory usage for the calling process and optionally the socket assigns.
Options
:socket
- Phoenix.LiveView.Socket to measure assigns memory:assigns
- List of assign keys to measure individually (e.g., [:dataclip, :workflow])
Wraps a function call with before/after memory logging.
Examples
measure("load dataclip", fn ->
Invocation.get_dataclip!(id)
end)
Measures memory of specific socket assigns.
Gets a memory snapshot as a map (useful for comparing before/after).