Chapter 16: Reusing Previous Computations
Chapter 16, Reusing Previous Computations, is now finished! This chapter focuses on invalidation, a technique that browsers use to avoid rendering work and speed up interactions.
Invalidation is well known to be a nest of bugs, performance issues, and subtle interactions. In fact, it’s one of Phil Karlton’s famous two hardest problems in computer science—so it’s no surprise that he worked on Netscape. Accordingly, this chapter is the most complex one that I’ve written.
My key goal was to make sure we not only described the basic techniques of validation, but that our implementation was correct or, better yet, obviously correct. Unfortunately, existing browsers actually don’t reach this bar—perhaps Chrome’s recent LayoutNG architecture is the closest—so this chapter introduces a new abstraction called ProtectedField
that, I hope, makes implementing complex invalidation schemes safe and easy.
Chris and I went through a huge number of variations in the course of writing this chapter. There are many, many ways to implement invalidation—it’s just that lots of them are subtly incorrect, or wouldn’t scale to a real browser. I feel pretty hopeful that we got it right in the end: ProtectedField
is relatively easy to use, allows readers to implement invalidation step by step, and still makes it hard to forget a dependency or forget to invalidate something.
Another challenge throughout this chapter was the need to make a number of small- and medium-sized changes to previous chapters to make Chapter 16 possible. It turns out that over the four years we’ve been writing this book, we made a few mistakes. But in software engineering and web-published books, mistakes can be fixed, so we did just that in a few cases. If you look carefully at some of the earlier chapters, you might notice the changes.
This is the last planned technical chapter of the book. Our hope is now to add some nontechnical content, clean up various design issues that have been bugging us, and move toward a complete, finished book sometime soon. More on that when we can!
Thanks as always to readers, and our supporters on Patreon. Please continue to give us feedback and tell your friends all about it. And follow our blog and Mastodon (or Twitter if you need it) to hear about future updates, and participate in the Github Discussions with questions and answers for the community.