Two times rendering

41 views
Skip to first unread message

Boris Kuznetsov

unread,
Aug 30, 2020, 3:38:18 PM8/30/20
to phoenix-core
Hi,

I'm writing application with LiveView and have an issue with component
rendering.

When we load a page with GET request, we get our live template
rendered. Second after that, if user-agent has javascript enabled, we
try to initialize socket connection and then we'll trigger rendering
again.

My concern is all heavy lifting needs to be done two times: on initial
page load and socket connection.

The only way to overcome this is to render component only via socket but
in such case you'll lose user-agents without js.

You can't skip initial socket rendering because you should set a state
to the socket connection.

To provide some context, let's imagine we'are writing repository page
for GitHub. We'll get many requests directly to that page and if we
would use LiveView, it looks like we would get many unnecessary requests
to our system.

Another good example would be Reddit website where you get many direct
page traffic.

Probably, we could flush state to the template (encrypted, signed) on
initial rendering and pass that state to the socket connection to avoid
double initialization issue.

Chris McCord

unread,
Aug 30, 2020, 9:43:16 PM8/30/20
to phoeni...@googlegroups.com
This is working as designed. As with anything else, optimize as necessary, cache as necessary, etc. "As necessary" is the key word here. You are correct we must perform the work in mount twice, but you also gain other benefits so the performance concerns are more nuanced. For example, the data you fetch and hang onto on mount (current user, preferences, roles, etc) will not have to be fetch again for user interactions, which are very frequent. So on the whole, you may find your LV use reduces the load on parts of your system. If you do run into performance walls, then standard rules apply – introduce cache, pool, etc, but don't worry about it until you actually run into a bottleneck. When in doubt, measure :)
> --
> You received this message because you are subscribed to the Google Groups "phoenix-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to phoenix-core...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/phoenix-core/m2mu2bx6u0.fsf%40achempion.com.

Boris Kuznetsov

unread,
Aug 31, 2020, 6:07:31 AM8/31/20
to phoeni...@googlegroups.com
Hi, Chris

What do you think about passong state through the DOM to eliminate
second data fetching? Is it reasonable optimization?
Reply all
Reply to author
Forward
0 new messages