-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize pattern matching on constants #1185
Comments
Investigating this a bit, it does not seem as though using a br_table is always the most efficent, if you have sparse datasets the table is not the best optionally additionally we need to map the data to a 0 based range as such it probably makes sense to use a few heuristics here notably:
We can however do an additional optimization when implementing this that is mentioned in the todo comment and even if the dataset is sparse we can load the number data from the heap and untag and do a direct match for some of our number types to speed things up. My current plan of attack is something like the following, (some furthur optimizations could be made such as on large match statements if we notice there are subranges of data we could break it into multiple chained jump tables or a mix of jumps and conditionals):
|
When matching on constants, we essentially compile something like
match (...) { 'a' => ..., 'b' => ..., ... }
into anif
chain ofif (val == 'a') { goto branch 1 } else if (val == 'b') { goto branch 2 } else ...
. We can instead compile them as though they were variants, and just do abr_table
.The text was updated successfully, but these errors were encountered: