Grist (self-host) is slow on first operations

I am self hosting Grist on a hosted server using Yunohost. I created a document which is about 6MB on disk (the SQLite database size). I mostly interact via API. I noticed that the first operation I run after a while (say first time during the day or in a few hours) it will often take 5-10 seconds to complete. Subsequent operations after that will take a few hundred milliseconds at most.

Is this expected behavior? Any recommended path to speeding it up? I’m not particularly memory constrained and there isn’t a ton else going on on the server. I tried switching the SQLite mode to WAL but it didn’t solve this issue.

Hi @jxk742.

Documents do exhibit a warm-up period when accessed for the first time. This is typically the case when no browser clients currently have the document open, and you try to access the document after a timeout period (~30 seconds), including via an API call. The length of the warm-up period scales with the size and complexity of the document, as tables and rows need to be loaded, formulas calculated, etc.

I don’t believe we have a way to configure this behavior right now. It would be useful to be able to do so (perhaps on a per-document level, as the current behavior exists for good reason – to reclaim unused memory when documents are not in use).

George

I have the same problem with forms : they require 5-6 seconds to open. If I re-open it immediately after it opens rapidly.

Those 5-6 seconds are a problem, many users give up before the form opens…

Thanks @georgegevoian! Could you point to roughly in the code where the cleanup / cache expiration happens? Want to see if we can either work around it or possibly submit a PR. Being able to configure it, even globally or at the document level would be super helpful.

It’s controlled by this variable: grist-core/app/server/lib/ActiveDoc.ts at main · gristlabs/grist-core · GitHub .

George