Answer the question
In order to leave comments, you need to log in
How to speed up rendering of nested simple_fields_for fields?
There are two models (product and product characteristics) connected by has_one association
There is a form - divided into two logical parts
1 For editing fields common for all products
2 Fields specific for this category
There are no questions with the first part. We use simple_form_for for the entry pulled from the database and render f.inputs. Everything is pretty slick.
But as we get to the parsial of additional fields, big brakes appear
I declare a simple_fields_for block in which we render all the same inputs for the associated characteristic record pulled from the database. So the server needs about ~ 100ms to render one checkbox. I have already thrown out everything superfluous from the extra fields parsial code. Leaving only the render of 20 checkboxes. But that was not the case WebRick claims that it takes 2 seconds to render this parshial. And the combat form hangs for 6 seconds only in this place. What could be wrong here? (I don’t even know about bringing the code - there’s nothing special to look at there).
It seems that in order to find out the state of the checkbox to display, simple_form makes a new query to the database for each input. The server log says that when the page is loaded, there are three requests to the database: we select the user, the product, the characteristics, then the parsials are rendered ...
Rails 4.2.1, simple_form_for 3.1.0
Answer the question
In order to leave comments, you need to log in
In general, I found a solution !! It was on github in the bug reports section of the simple_form repository.
What is the expected slowdown of using SimpleForm?
There, Mr. nashby wrote something like this in March of this year:
Accordingly, substituting wherever placeholder: false, hint: false
possible. Got a boost from 6 seconds to 780ms.
Keep in mind in your applications;)
Without seeing the code, you can only wang.
6 seconds is a lot for one form. The reasons can be the following:
1. Poorly composed database queries, because of which the data loading takes too long (problem N + 1)
2. Poorly composed page / parsial structure. Parshals greatly slow down the rendering of the page, so it is worth optimizing the page structure and reducing the number of parsials
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question