Skip to content

Commit

Permalink
clarify tip about untyped globals: const globals need no annotation (J…
Browse files Browse the repository at this point in the history
…uliaLang#54379)

The performance tip from JuliaLang#43671 by @simeonschaub 

> If a global is known to always be of the same type, [the type should
be
annotated](https://docs.julialang.org/en/v1/manual/variables-and-scoping/#man-typed-globals).

was a bit unclear to me, because it does not apply to `const` globals
(whose type requires no annotation). This PR clarifies that point
  • Loading branch information
stevengj authored and lazarusA committed Jul 12, 2024
1 parent d6085b1 commit e174965
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion doc/src/manual/performance-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ performance:
const DEFAULT_VAL = 0
```

If a global is known to always be of the same type, [the type should be annotated](@ref man-typed-globals).
If a non-constant global is known to always be of the same type, [the type should be annotated](@ref man-typed-globals); `const` globals need not be annotated because their type is inferred from their initialization value.

Uses of untyped globals can be optimized by annotating their types at the point of use:

Expand Down

0 comments on commit e174965

Please sign in to comment.