In this chapter, we explored several patterns related to performance.Â
First, we discussed how global variables hurt performance and the technique of the global constant pattern. We looked into how the compiler optimizes performance by doing constant folding, constant propagation, and dead branch elimination. We also learned how to create a constant placeholder for wrapping a global variable.
We discussed how to utilize the struct of arrays pattern to turn an array of structs into a struct of arrays. The new layout of the data structure allows better CPU optimization and, hence, better performance. We took advantage of a very useful package, StructArrays, for automating such data structure transformation. We reviewed a financial services use case where a large amount of data needs to be loaded into memory and used by many parallel processes. We implemented the shared...