phetsims / gene-expression-essentials

An educational simulation about how genes work to create proteins.
GNU General Public License v3.0
4 stars 6 forks source link

memory profile testing #107

Closed jbphet closed 6 years ago

jbphet commented 6 years ago

I'm about to test the memory usage, looking for leaks, and it would be good to have a record of it. I'm testing on master as of today so that I don't have to deal with uglified names. I'm testing in RequireJS mode except where noted. All tests are run on a fresh load in an incognito window in Chrome, version Version 61.0.3163.100 (Official Build) (64-bit) on Windows 10.

jbphet commented 6 years ago

Targeted Tests

Before doing these tests I did an experiment where I started the sim, went to the first screen, took a heap snapshot, then dragged several biomolecules out of the toolbox, then took another heap snapshot, and then compared the two. I did this in order to verify that I can see the allocated biomolecules, their associated view nodes, state machines, and states in the memory profile. And indeed, these allocations are visible when the snapshots are compared.

Targeted Test 1: Go to screen 1, take a heap snapshot, then drag out all the available biomolecules, let them float around for a while, then put them all back, take a snapshot and compare the results. Result: There are no biomolecules leaked, but there was an increase in the number of vectors allocated, and the number matched the number of biomolecules. I repeated the test several times to see if vectors were leaking, and they weren't, so I think a Vector2 is allocated the first time a biomolecule is created and then stays around. So basically, this is a pass. Note: There are a lot of other things that are allocated during this test, but as far as I can tell these are the pooled Scenery resources that I've seen before. Example:

Targeted Test 2: Go to screen 1, take a heap snapshot, do all the activities necessary to transcribe and translate the gene and create the protein. Destroy the mRNA, then put all the biomolecules back in the toolbox (don't forget the transcription factor on the DNA), leave the protein floating, and take a heap snapshot. Verify that the protein and associated objects (such as the BiomoleculeNode and the states and state machine) appear in the heap snapshot, but no other biomolecules or mRNA fragments are there. Then collect the protein and take another heap snapshot. Verify that the objects associated with the protein are removed from the heap when the snapshots are compared. Result: Pass.

Targeted Test 3: Go to screen 1, take a heap snapshot, generate and collect a protein for each gene, not putting away any of the biomolecules that are used. Hit the reset button, and take another snapshot, and compare the two. Verify that there are not biomolecules, states, or biomolecule nodes in the snapshot when compared with the initial one. Result: Pass.

Targeted Test 4: Go to screen 2, take a heap snapshot, then turn up the concentration of positive transcriptions factors to the max level, let at least 3 transcriptions of mRNA occur, then hit the reset button, then take another heap snapshot. Compare the two snapshots and verify that there is are no transcription factors still around, and verify that there is no net gain of RnaPolymerase instances nor of the view nodes, states, state machines, and motion strategies associated with them. Result: Pass.

Targeted Test 5: Go to screen 2, take a heap snapshot, then turn up the concentration of positive transcription factors to the max and allow at least three transcriptions to occur. Turn down the concentration of positive transcription factors, then enable negative transcription factors and turn their concentration up to the max and let them bounce around for ~10 seconds. Turn the negative transcription factor concentration back down to the minimum and disable negative transcription factors. Wait ~10 seconds, then take a heap snapshot. Compare the snapshots and verify that there are no instances of positive or negative transcription factors, no messenger RNA instances, and no net gain of RnaPolymerase instances nor of the view nodes, states, state machines, and motion strategies associated with them. Result: Pass

Targeted Test 6: Go to screen 3, take a heap snapshot, then increase the number of cells to the max value, then back to the min value. Take another heap snapshot and compare the two. Verify that there is no gain in allocations of cells or cell nodes. Result: Pass

jbphet commented 6 years ago

Fuzz Tests

Baseline values;

Fuzz test, snapshot size minutes after load:

Time (minutes) Snapshot Size (MB)
0 49.7
1 54.1
2 56.3
3 56.6
4 58.3
5 57.4
6 58.5
7 58.1
8 59.7
9 61.3
10 59.0

I also stopped the fuzzing shortly after minute 10 by using the phet.chipper.queryParameters.fuzzMouse=false command in the console, then reset each screen. The heap snapshot at that point was 57.9 MB. I did some basic testing of each screen at this point, and they all seemed fully functional.

jbphet commented 6 years ago

Overall, the memory behavior looks good. The targeted testing detected no leaks. The memory usage during fuzz testing peaked at 61.3 MB, but then came down a bit, and held pretty steady in the 55-61MB range once the initial ramp up occurred. I'm not seeing anything that should block publication or warrants further investigation. Closing.