How big is the memory footprint of each empty LiveView's assigns?

Or, put it other way, what is the memory cost of having 1.000 temporary_assign values set to [] or nil?
I was refactoring my project into LiveView components and I got this question: “What if I changed all my static assigns from old Phoenix templates to dynamic LiveView assigns for all my styling?”
Imagine I would have something like this inside a LiveView:

def mount(socket) do
  socket = assign(socket, styleOne: "width: 100%; margin: 1.5rem;",
                          styleTwo: "width: 100%; padding: 0.25rem; background-color: White",
                          styleThree: "width: 100%")
 {:ok, socket, temporary_assigns: [styleOne: nil, styleTwo: nil, styleThree: nil]}

def render(assigns) do
      <div style="<%=@styleOne%>">
              <div style="<%=@styleTwo%>">Text</div>
              <div style="<%=@styleThree%>">...</div>

There are several WHY reasons for that, one of them would be to easily allow users to customise some styling on some elements if needed.
But this is also a more architectural theoretical question :slight_smile:

I think the easiest way to find out is to actually try it and introspect what is going on, using liveSocket.enableDebug() (see debugging Client events in the LiveView documentation).

1 Like

I think with that we can only get what is being sent over the network.
My goal is on the server side. How much each of these need from memory. I guess it should be a small constant, but would like to know if anyone knows exactly (or if it’s not that simple).

Ah, in that case you can still do the same thing, but then rather than checking it in the JavaScript console, you can check how much memory the particular socket process is using by opening Observer (:observer.start) from IEx.