Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow processes to be named. #198

Merged
merged 1 commit into from
Jul 12, 2024
Merged

Allow processes to be named. #198

merged 1 commit into from
Jul 12, 2024

Conversation

plietar
Copy link
Member

@plietar plietar commented Jul 11, 2024

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

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.
@plietar plietar requested a review from giovannic July 11, 2024 17:16
@plietar
Copy link
Member Author

plietar commented Jul 11, 2024

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 plietar/malariasimulation#13, waiting for results.

Copy link
Member

@giovannic giovannic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for figuring that out!

@giovannic
Copy link
Member

Note: we would want to update dev too.

@plietar plietar changed the base branch from master to dev July 12, 2024 10:07
@plietar
Copy link
Member Author

plietar commented Jul 12, 2024

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

@plietar plietar merged commit 3d199bc into dev Jul 12, 2024
6 checks passed
@plietar plietar deleted the named-processes branch July 12, 2024 10:08
plietar added a commit to mrc-ide/malariasimulation that referenced this pull request Jul 12, 2024
Thanks to [individual#198], processes in the simulation can now be
named. This has no effect on the behaviour of the simulation but helps
in debugging and profiling by labelling the call frames with the given
names.

While at it, I've fixed a typo in the name of the prevalence renderer.

[individual#198]: mrc-ide/individual#198
plietar added a commit to mrc-ide/malariasimulation that referenced this pull request Jul 12, 2024
Thanks to [individual#198], processes in the simulation can now be
named. This has no effect on the behaviour of the simulation but helps
in debugging and profiling by labelling the call frames with the given
names.

While at it, I've fixed a typo in the name of the prevalence renderer.

[individual#198]: mrc-ide/individual#198
plietar added a commit to mrc-ide/malariasimulation that referenced this pull request Jul 12, 2024
Thanks to [individual#198], processes in the simulation can now be
named. This has no effect on the behaviour of the simulation but helps
in debugging and profiling by labelling the call frames with the given
names.

While at it, I've fixed a typo in the name of the prevalence renderer.

[individual#198]: mrc-ide/individual#198
plietar added a commit to mrc-ide/malariasimulation that referenced this pull request Jul 22, 2024
Thanks to [individual#198], processes in the simulation can now be
named. This has no effect on the behaviour of the simulation but helps
in debugging and profiling by labelling the call frames with the given
names.

[individual#198]: mrc-ide/individual#198
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants