Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.91k stars 542 forks source link

[feature] optimized OPs for some common patterns #17190

Open atoomic opened 4 years ago

atoomic commented 4 years ago

Devel::GoFaster provide a prototype to optimize the optree for some common patterns

//= 1

@arc was also suggesting in https://github.com/p5h/p5summit-2019/issues/18 to consider

EXPR ? 1 : 0 and !!EXPR
1 - !EXPR
richardleach commented 1 year ago

Some questions:

//= 1

Literally this just that, or //= ANYCONSTANT

EXPR ? 1 : 0 and !!EXPR 1 - !EXPR

What are some common examples of this in the wild? Are these definitely hot patterns?

Note: Devel::GoFaster looks to optimize my $x = shift and my $x = shift // INT. I've started looking into a core optimization that could handle all of these:

  my $x = shift
  my $x = shift // ANYCONSTANT
  my $x = shift || ANYCONSTANT
  my $x = shift // ANON_HASH_OR_ARRAY
  my $x = shift || ANON_HASH_OR_ARRAY
Tux commented 1 year ago

Why exclude CODE and GLOB. I think I used and use all variants of my $x = shift // Any;

richardleach commented 1 year ago

I think I used and use all variants of my $x = shift // Any;

Yeah. I was thinking about known-simple and common op structures that could be reduced to 1 or two ops, but could make it jump to arbitrary Any trees as well.