Summary

In this chapter, we dived into the bytecode representation and performance considerations of commonly-used Scala language features. In our case study, you saw first-hand how you can combine several areas of knowledge about Scala language features in combination with the excellent Scalaz library to produce an Option implementation that is better suited for high-performance needs.

A consistent theme across all our examples is to promote type-safety and correctness while taking into account performance tradeoffs. As functional programmers, we value compile time correctness and referential transparency. Even with the usage of null in the tagged type Option implementation, we preserved correctness because the null value is an internal implementation detail. When you reflect on the strategies that we covered, consider how each one preserves referentially transparent (that is, side-effect-free) code while still enabling you to reach your performance goals.

At this point, you should feel more confident about the tradeoffs that are introduced by Scala's elegant language features. Through our analysis, you learned how to translate from concise Scala syntax to JVM bytecode. This is an invaluable skill to debug performance issues. As you practice your awareness by studying more examples, you will develop a stronger intuition for where potential problems lie. Over time, you can refer back to this chapter in order to review common remediation strategies to balance the tradeoff between elegance and safety with performance. In the next chapter, we will continue to grow our ability to leverage Scala to write performant, functional code by diving into collections.

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

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