<function>
or <operator>
).
This is just notation, and the symbols <
and >
should not be misconstrued as Julia's syntax.
Action | Keyboard Shortcut |
---|---|
Previous Section | Ctrl + 🠘 |
Next Section | Ctrl + 🠚 |
List of Sections | Ctrl + z |
List of Subsections | Ctrl + x |
Close Any Popped Up Window (like this one) | Esc |
Open All Codes and Outputs in a Post | Alt + 🠛 |
Close All Codes and Outputs in a Post | Alt + 🠙 |
Unit | Acronym | Measure in Seconds |
---|---|---|
Seconds | s | 1 |
Milliseconds | ms | 10-3 |
Microseconds | μs | 10-6 |
Nanoseconds | ns | 10-9 |
In the upcoming chapters, we'll focus on two crucial aspects for performance: type stability and reductions in memory allocation. They constitute the most basic procedures to achieve high performance, thus acting as the starting point for further optimizations.
This chapter in particular focuses on type stability, whose importance for Julia can't be overstated—any attempt to generate fast code without ensuring type stability is destined to fail.
At the core of type stability is the way computers perform operations at a fundamental level. This entails that, regardless of the programming languages, the approach to computing operations differs depending on the inputs' types. For instance, the underlying process for integers differs from the one for floating-point numbers.
In light of this, high performance in Julia requires operations to be type-stable. This means that Julia must be able to identify a specific type for each variable to specialize its computation method. If this isn't possible, Julia is forced to generate code that handles multiple potential approaches, one for each possible combination of input types. This introduces additional runtime checks and type conversions, significantly degrading execution speed.
The discussion of type stability will be intertwined with functions, as attaining type stability requires wrapping code in a function. The reason is that Julia doesn't identify types of variables in the global scope. In contrast, functions start by identifying each local variable's type, making method specialization possible. Wrapping code in a function is only a necessary condition for type stability, and the chapter will provide additional conditions to guarantee the property.