mrc-ide / individual

R Package for individual based epidemiological models
https://mrc-ide.github.io/individual
Other
30 stars 16 forks source link

Allow processes to be named. #198

Closed plietar closed 4 months ago

plietar commented 4 months ago

Because of how R assigns names to stack frames, all processes in a typical individual simulation would end up being called p. This makes it difficult to interpret profiling results.

R uses the name of the variable the called function is bound to. By dynamically creating a variable with a chosen name and using eval to execute that variable, we can get the stack frame to show up with any desired name.

This uses this trick to allow the list of processes to be given names, and these names are used in the calls.

Below is a comparison of the before and after of looking at a malariasimulation profile. Instead of everything being grouped under a single p node, there are now distinct nodes for each process.

image image

plietar commented 4 months ago

Based on some quick local benchmarking there doesn't seem to be any measurable difference in performance with this.

I've kicked off a touchstone run on https://github.com/plietar/malariasimulation/pull/13, waiting for results.

giovannic commented 4 months ago

Note: we would want to update dev too.

plietar commented 4 months ago

Yeah that was definitely aimed at dev, I keep forgetting to set the right target branch