tozz

tozz

I’m currently seeing some issued with our admin interface, where people on Intel CPU’s being shown the “the tab has crashed” kind of dialog when using a LiveView form. The background is that we use the Ecto sort and delete params, interactions need to be processed, otherwise I’d just change it to not have any interactive features.

The issue is not on the receiving end, that’s significantly much faster, but when LiveView does its processing before dispatching to the server. This screenshot is on a M3 Pro.

I don’t know why dispatchClickAway is wrapping all this, since there’s no such event on the page :slight_smile:
I tried digging deeper but as you know with JS, it’s usually a very long list of anonymous functions with minified names.

Looking at Node count it varies between 80-800K. Yes that’s 10x, for some reason LiveView or Chrome, unclear which, don’t clean up the tree after navigating/getting updates. It seems to be reliant on a GC to run.

The form is quite straight forward.

Schema (120 entries), 
|---- SubSchema (can vary, but between 0 and 10 items)
|---- SecondSubSchema (0-3 items)

So at most one level deep, but you can add and remove them dynamically. Processing times on the server side are fast enough that it doesn’t matter, less than 20ms, even in dev-mode.

Curious as to if people have some good ideas on how to debug this.

Showing Posts 1 to 10

chrismccord

chrismccord

Creator of Phoenix

We’d need to know a lot more. 80k DOM nodes is extreme, 800k is likely to be a showstopper in general, but I haven’t measured. facebook.com timeline for example is on the order of 4-5k DOM nodes. What is your DOM node count on dead render/first mount?

tozz

tozz OP

I dug into this some more, my numbers are from the Chrome Performance Monitor, and it seems that is doing some weird counting, or it keeps some internal state that isn’t represented in the actual tree.
Doing a simple document.querySelectorAll('*'); returns 19k nodes. Looking at just input it’s 4600 (actually exact) and of those it’s 2450 that are hidden (inputs_for generated with the exception of the needed _sort / _delete ones for Ecto)

Looking at execution time pushInput is the one function taking up time, below is a screenshot of dynamically adding three new “SubSchemas” to the form on a M1.

Happy to supply any other data you might need, and thank you for all the hard work in the ecosystem, using Phoenix and LiveView has been a bliss in general :slight_smile:

tozz

tozz OP

@chrismccord I found the “problem” (at least one that is really really tangible).

In serializeForm there’s a section that really destroys performance.

// view.js
let elements = Array.from(form.elements);
for (let [key, val] of formData.entries()) {
...
  let inputs = elements.filter(input => input.name === key)
  let isUnused = !inputs.some(input => (DOM.private(input, PHX_HAS_FOCUSED) || DOM.private(input, PHX_HAS_SUBMITTED)))
  let hidden = inputs.every(input => input.type === "hidden")
...
}

That first filter is very costly, in my form that’s a total of 22036236 iterations (I added a counter :smiley:). And I’d argue this isn’t even a big form, given the context of building an admin interface.

abuislam

abuislam

I’ve run into similar issues with JavaScript timeouts before—optimizing event handling and reducing unnecessary re-renders helped in my case. Are you using debounce or throttle for frequent updates? Hope you find a fix soon!

tcoopman

tcoopman

How is that 22 milion iterations?
The square root of that is something in the order of 4900, so you have form.elements and formData.entries in the order of 4-5K?

That sounds like a big form in my book?

But if this is the bottleneck for you, you might try to optimize the code yourself and see if you can improve the performance and submit a PR?

tozz

tozz OP

As mentioned in the original post, yes it’s 4600 inputs, more than half of them are inputs_for generated and _sort/_delete hidden fields. The form itself is not very large, it’s for building a Questionnaire, each Questionnaire have questions, questions have answer options. Then again, “large” is relative and I might just have a different background. It could very well be that I’m not supposed to use LiveView for this, but it would be truly marvelous if I could.

But if this is the bottleneck for you, you might try to optimize the code yourself and see if you can improve the performance and submit a PR?

Exactly what I’ve been doing, but there’s a lot of moving parts here.
Storing the lookup on input.name saves 4m iterations, but it’s still way too high, but a free optimization (unless it breaks somewhere else of course).

tcoopman

tcoopman

I think if you want really improve the performance, then I think you need to look at changing the algorithm. For example by breaking the O(n^2) algorithm by introducing an other datastructure. For example by parsing the form elements in a map with name as a key.

But you’d have to do some benchmark to see if that has a decent effect.

Schultzer

Schultzer

If you have a lot of text input, then it is highly advisable to disable default attributes like spellcheck spellcheck HTML global attribute - HTML | MDN and autocomplete <form> HTML form element - HTML | MDN

Schultzer

Schultzer

Phoenix does a lot in JS, especially with watching forms and helping with focus and etc. It does a bit to much for my taste and I think it could benefit from doing less on the front end and more on the backend and just leverage messages passing to reconcile states, I believe the cost in increase chatter will be worth it when messages are small.

tozz

tozz OP

It would be interesting with a server-first forms solution, it would of course come with its own tradeoffs (like not being able to recover, or at least making it much harder).

Removing this inner loop makes everything work blazing fast, and from what I can tell the only purpose for it is to control what field has been used to trigger showing of errors, which of course is a big UX thing.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews