Crafting Interpreters · Week 15
Crafting Interpreters 28: Methods and Initializers: reading guide
Read the chapterVerified by tests
Methods, bound methods, this, initializers, and the OP_INVOKE optimization that combines property lookup and call.
Time About 7 hours this week
Why it matters
The invoke optimization is a real technique that production VMs use, and you get to measure its effect.
How to approach it
Benchmark method calls before and after OP_INVOKE.
Challenges
3 challenges at the end of the chapter.
Challenge 1 (faster init lookup) is quick. Challenge 2 is about inline caching, which is how fast JS engines work; reading about it is worthwhile even if you do not implement it.
Traps
- Not handling the case where a field shadows a method in OP_INVOKE.
- Leaking bound method objects or forgetting to mark them.
Verified by the book's chap28_methods tests when you push your repo.