Chapter 6
Why does the use of global variables impact performance?
Global variables are not typed. Whenever it is used, the compiler must generate code that handles any possible data types that it may encounter. Hence, the compiler cannot generate highly-optimized code.
What would be a good alternative to using a global variable when it cannot be replaced by a constant?
We can define a typed global constant as a placeholder. The Ref type may also be used to hold a single value for the variable. Because Ref contains the type of data, the compiler can generate more optimized code.
Why does a struct of arrays perform better than an array of structs?
Modern CPUs can perform many numerical calculations in parallel. When the memory is aligned and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access