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

Store global variables in a const structure #30

Open
dpsanders opened this issue Feb 7, 2022 · 2 comments · Fixed by #35
Open

Store global variables in a const structure #30

dpsanders opened this issue Feb 7, 2022 · 2 comments · Fixed by #35

Comments

@dpsanders
Copy link

dpsanders commented Feb 7, 2022

Using global variables as in

global steps = 200 # discretization levels of probability

is a performance trap.

To fix this, I suggest grouping all the global variables into a mutable struct, which you refer to via a const global. See e.g.

https://github.com/JuliaIntervals/IntervalArithmetic.jl/blob/db9202ccd08402d05616442f395e88cb21f79b9b/src/intervals/precision.jl

for a similar design.

@dpsanders dpsanders changed the title Store variables in a const structure Store global variables in a const structure Feb 7, 2022
@dpsanders
Copy link
Author

Part of the review for the JuliaCon proceedings: JuliaCon/proceedings-review#96

@AnderGray
Copy link
Owner

Thank you for this suggestion. I have followed the example from IntervalArithmetic.jl. In future it would be good to also remove these globals

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 a pull request may close this issue.

2 participants