Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

Callable.assuming() is slow #5369

Open p6rt opened 8 years ago

p6rt commented 8 years ago

Migrated from rt.perl.org#128388 (status was 'open')

Searchable as RT128388$

p6rt commented 8 years ago

From @hinrik

Calling .assuming() on a subroutine is way too slow for general usage.

$ time perl6 -e'sub foo { my &curry = &foo.assuming(); }; for 1..100 -> $x { foo() }'

real 0m4.235s user 0m4.192s sys 0m0.044s

$ time perl6 -e'sub foo { }; for 1..100 -> $x { foo() }' real 0m0.106s user 0m0.068s sys 0m0.036s

p6rt commented 8 years ago

From @smls

Agreed.

It's also not thread-safe (see ticket #​127987), and its implementation is a real mess of spaghetti code. I think it's a safe bet that at some point that whole method will be rewritten, and that'll hopefully fix its slowness too.

For now, you can use a closure instead. So for example instead of this​:

  my &float-to-str = &sprintf.assuming("%f");

...write this​:

  my &float-to-str = { sprintf "%f", $_ };

In the general case (when you don't know how many and what type of variable parameters will be passed), the following two should behave the same​:

  &f.assuming($a, $b)

  -> |c { f $a, $b, |c }

p6rt commented 8 years ago

The RT System itself - Status changed from 'new' to 'open'