Summary

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 array pattern and went over some tricks to configure shared memory properly in the operating system.

We learned about the memoization pattern for caching function call results. We did a sample implementation using a dictionary cache and made it work with functions taking various arguments and keyword arguments. We also found a way to support mutable objects as function arguments. Finally, we discussed the barrier function pattern. We saw how performance can be degraded by type-unstable variables. We learned that splitting logic into a separate function allows the compiler to produce more optimal code. 

In the next chapter, we will examine several patterns that improve system maintainability.

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

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