Skip to content

Commit 3254676

Browse files
jonas-eschleViralBShahfredrikekre
authored andcommitted
WIP: Clarify performance penalty of global (JuliaLang#42452)
* Clarify performance penalty of global I've slightly changed the wording for why a global creates a penalty in performance, as it raised confusion [such as here](https://discourse.julialang.org/t/global-variables-const-by-default/33138/3?) and I think the current wording was wrong (changing the value does not need to change the type, correct?) However, I am still not quite convinced as a variable *doesn't* has a type and therefore "it's type changes" seems a bit weird, doesn't it? * Update performance-tips.md * Update performance-tips.md * Update performance-tips.md * Update performance-tips.md * Update performance-tips.md * Update doc/src/manual/performance-tips.md Co-authored-by: Viral B. Shah <[email protected]> Co-authored-by: Fredrik Ekre <[email protected]>
1 parent c384809 commit 3254676

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

doc/src/manual/performance-tips.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ The functions should take arguments, instead of operating directly on global var
1313

1414
## Avoid global variables
1515

16-
A global variable might have its value, and therefore its type, change at any point. This makes
17-
it difficult for the compiler to optimize code using global variables. This also applies to type-valued variables, i.e. type aliases on the global level.
18-
Variables should be local, or passed as arguments to functions, whenever possible.
19-
16+
A global variable might have its value, and therefore possibly its type, changed at any point. This makes
17+
it difficult for the compiler to optimize code using global variables. This also applies to type-valued variables,
18+
i.e. type aliases on the global level. Variables should be local, or passed as arguments to functions, whenever possible.
2019

2120
We find that global names are frequently constants, and declaring them as such greatly improves
2221
performance:

0 commit comments

Comments
 (0)