After we have done tons of way to improve loading performance such as adding index to database, using eager loading, void N+1 issue, getting rid of O(n2), pagination etc, the page loading is still slow?!
The problem left is the data we load. We tend to store base64 of file content in database in modern development instead of upload physical file to cloud. If we load hundreds or even thousands of records including base64 string like below which is huge data.
We select the attributes we want instead, skip base64 attributes.
@pagy, @eforms = pagy(eforms.select(:file_name, :display_name, :form_objects, :updated_at), items: 10)
We would find that the solution is very simple. Loading data instantly. We we haven’t encountered the problem of massive string like this we might not understand the effective of “select” attributes.