-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
VM pattern code less efficient than manual check #54114
Comments
/cc @alexmarkov |
@alexmarkov I would love to learn from how you approach this - if you could cc me on changes I would be grateful. |
Flow graph:
Optimizer can match an empty basic block ( However, before implementing this optimization, I'd like to figure out why CFE created such lowering at the first place. Kernel:
CFE could use
With this lowering, right-hand side of @johnniwinther @chloestefantsova Is there any reason to use ternary @rakudrama How would this change in pattern lowering affect dart2js? |
If I compile this with
dart compile exe
(and flags to dump disassemble), the code for thepattern
method is less efficient than the other two.The
manual
andpromote
methods both compile to function code (minus intro/stack check) of:That's basically
$tmp = this._x; if ($tmp != null) print ($tmp); else print("null"); return null;
The pattern version produces:
which is closer to:
It looks like some desugaring of patterns ends up reifying the match result as a boolean value, and introducing a temporary variable for the non-matching branch too, in a way that the VM compiler doesn't manage (or try?) to optimize afterwards.
I'd prefer to use the
case
version, but only if it's actually as efficient.The text was updated successfully, but these errors were encountered: