Skip to content

Commit 3909294

Browse files
authored
Performance tips updated on abstract type params and annotations (#36829)
1 parent 9267bbf commit 3909294

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

doc/src/manual/performance-tips.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ julia> push!(a, 1); push!(a, 2.0); push!(a, π)
189189
Assigning numbers into `a` will now convert them to `Float64` and `a` will be stored as
190190
a contiguous block of 64-bit floating-point values that can be manipulated efficiently.
191191

192+
If you cannot avoid containers with abstract value types, it is sometimes better to
193+
parametrize with `Any` to avoid runtime type checking. E.g. `IdDict{Any, Any}` performs
194+
better than `IdDict{Type, Vector}`
195+
192196
See also the discussion under [Parametric Types](@ref).
193197

194198
## Type declarations
@@ -453,9 +457,9 @@ annotation in this context in order to achieve type stability. This is because t
453457
cannot deduce the type of the return value of a function, even `convert`, unless the types of
454458
all the function's arguments are known.
455459

456-
Type annotation will not enhance (and can actually hinder) performance if the type is constructed
457-
at run-time. This is because the compiler cannot use the annotation to specialize the subsequent
458-
code, and the type-check itself takes time. For example, in the code:
460+
Type annotation will not enhance (and can actually hinder) performance if the type is abstract,
461+
or constructed at run-time. This is because the compiler cannot use the annotation to specialize
462+
the subsequent code, and the type-check itself takes time. For example, in the code:
459463

460464
```julia
461465
function nr(a, prec)

0 commit comments

Comments
 (0)