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 packed together as in an array, the hardware cache can quickly look them up. An array of structs may have the objects scattered around in memory, which hurts performance.

What are the limitations of SharedArray?

SharedArray only supports bit types. If we need to process non-bits type data in parallel, then we cannot use SharedArrays.

What is an alternative to multi-core computation instead of using parallel processes?

An alternative is to use the multithreading facility. The Julia 1.3 release implemented a state-of-the-art multi-threading scheduler that supports multiple levels of parallelism.

What kind of care must be taken when using the memoization pattern?

Memoization trades space with time. The use of a cache demands more memory space. Depending on the function result, it may or may not impact the memory footprint of the application. If memory is already constrained in the system, it may not be the best option.

What is the magic behind the barrier function in improving performance?

When using the barrier function, the compiler can specialize the function based upon the types of arguments being passed to the function. Even though the type of argument is unstable, when a new type is encountered, a new specialized function is compiled automatically.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset