The 128-arm pattern dispatch problem and how we got from 11ns to 1.1ns
The problem Pattern matching on a large set of literal values looks clean in code but hits a wall at runtime. Every on() call constructs case objects for every arm. With 128 arms, that is 128 object constructions per match call. At 11ns per call, this is fine for one-off use. Inside a hot loop, it is a disaster. // Clean syntax, 128 case objects constructed per call return match ( x ) | on ( lit ( 0 ) >> handle_0 , lit ( 1 ) >> handle_1 , // ... 126 more arms _ >> default_handler ); The cases ar
Comment
Sign in to join the discussion.
Loading comments…