Situation
I have a SPA with a few pages displaying collections of items. In one of these pages, I have a listing of the items where for each item a summary is displayed as a row item and when that row is clicked, a more detailed version of the row is being displayed inline.
On the development dataset (few items in each collection) everything works alright but when I moved to a production dataset the app (few thousands items in some of the collections) everything slows to a halt. Now, clicking on a row to get the detailed version takes around 1 second. The collections are kept in a session
record as Dict
with a String Id as key.
What I tried
I have a filter function for the items and I tried to force the listing to only 10 items. This improves the situation a little bit but the app is still quite unresponsive.
The app runs on 0.18
and so I was able to use the instructions from this thread:
https://discourse.elm-lang.org/t/very-useful-function-when-optimizing-render/1517/5
The Debug.logTime
function proved to be a wonderful investigative tool but it reveled something strange.
I used it like this:
main : Program Flags Model Msg
main =
Navigation.programWithFlags
(RouteTo << Route.fromLocation)
{ init = init
, update = \msg -> Debug.logTime "update" (update msg)
, view = Debug.logTime "mainView" view
, subscriptions = subscriptions
}
This is how the performance recording looks like for two clicks (one to show the details and one to hide them for one of the items):
The largest part of the time seams to be spent in the runtime. For each click there are 3 calls to update that are barely visible. One of the calls can be optimized away by restructuring the code but the problem remains.
Any hints or ideas of what else I could try are welcomed.
LATER EDIT:
the vast majority of the time took by the runtime was due to --debug
. Thanks @dmy for the hint.
LATER EDIT2:
It looks like part of the delay that I’m still seeing is caused by the fact that DevTools is open.