This is a script which switches between the messages and contacts tab every 5 seconds.
setInterval(() => $('#messages-tab').click(), 5000);
setTimeout(() => setInterval(() => $('#contacts-tab').click(), 5000), 2000);
I did the following:
Results after waiting 10 minutes:
Metric | Before | After
-- | -- | --
Heap | 163MB | 195 MB
DOM Nodes | 17,000 | 410,000
A second run for 5 minute without live-list drawing in contacts tab:
Metric | Before | After
-- | -- | --
Heap | 126MB | 327MB
DOM Nodes | 17,000 | 200,000
Measures imply some sort of resource leak. This was on Chrome 70, so could be bogus. Worth investigating further.
@kennsippell were the chrome dev tools open or closed when you did these tests?
@SCdF Open. I haven't attempted to measure precisely, but still appears to be a leak (slower) when closed. You have good reading on the impact of DevTools on this?
@kennsippell definitely not a good reading, but I have noticed that leaving dev tools open overnight in our app (so not changing tabs, just completely idle, and against an idle local DB) can often cause huge amounts of ram usage for the tab and often a lot of cpu usage.
However, I have not put effort into replicating or isolating this-- sometimes I just wake up after working on webapp the day before and my laptop fan goes nuts. I have just always presumed that dev tools === slow + dodginess. That could be a bad presumption though...
I may have a fix for this, or at least a partial one.
I found some leaks that are easily avoidable.
@kennsippell I've pushed some changes to a branch, as an attempt to fix some of these memory leaks.
I've touched Messages, Contacts and Reports.
If you find the time, could you please checkout and re-run the tests with these changes? Thanks in advance!
@dianabarsan Added most recent measures into the PR.
The actual leak is not as severe as reported above. My chrome extensions were interfering.
To AT, follow these steps:
(() => {
let i = 0;
const mInterval = setInterval(() => {
if (i % 5 === 0) $('#messages-tab').click();
if (i % 5 === 1) $('#tasks-tab').click();
if (i % 5 === 2) $('#reports-tab').click();
if (i % 5 === 3) $('#contacts-tab').click();
if (i % 5 === 4) $('#analytics-tab').click();
if (++i > 100) {
clearInterval(mInterval);
}
}, 2500);
})();
(2500ms was enough of a timeout to load any tab completely on my PC, but you can increase this interval if it's too low).
Let the script finish. You should be back to the messages tab now. Repeat from step 4, recording the 3 metrics after every iteration. Repeat as many times as you like, maybe at least 4 times.
Compare metrics across iterations. Slight variations are normal. It's very important to force garbage collection before recording.
There is also more information/discussions on the PR: https://github.com/medic/medic-webapp/pull/5073#issuecomment-445877319
There seems to be a linear increase the heap size each run (even after running the garbage collector).... but not a big difference.

Run 1

Run 2

Run 3

Run 4

Run 5

Run 6

@ngaruko
Are you sure you are following the steps exactly, including running the tests with a closed dev tools in an incognito browser?
I ran them again, myself, on gamma.dev with a restricted user and these are my results:

A total of 6 runs, for the last 2 I included the performance status before clicking on the garbage collect button too.
Can you please tell me how and where you are testing this, so I can try to replicate?
Running the test 4 times on gamma.dev, logged in as the user indicated by @ngaruko

LGTM
Thanks @dianabarsan

Most helpful comment
To AT, follow these steps:
(2500ms was enough of a timeout to load any tab completely on my PC, but you can increase this interval if it's too low).
Let the script finish. You should be back to the messages tab now. Repeat from step 4, recording the 3 metrics after every iteration. Repeat as many times as you like, maybe at least 4 times.
Compare metrics across iterations. Slight variations are normal. It's very important to force garbage collection before recording.
There is also more information/discussions on the PR: https://github.com/medic/medic-webapp/pull/5073#issuecomment-445877319