4 ms·
The Point of Pattern Matching in Scala (2009)
- vbezhenar 11y ago> with modern VM technology it's (pattern visitor) way more innefficient than pattern matching Can someone explain that bit? Visitor pattern is 2 virtual calls. That should be very efficient. How pattern matching is more efficient?
- mamon 11y ago2 virtual calls are required to simply get Visitor's logic executed. But if you want your Visitor to actually do something usefull with visited object then you have to call a bunch of getters to extract the object data. This adds several more virtual calls. Pattern matching in Scala can be implemented as "messing with the bytecode", bypassing getters completely, which saves you all those virtual calls to them.