Re: Gain performances and fix some issues using XS
[email protected] (Steev)
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <CAKGzny1Wryds2+=OiqidYiX-WLabNXB86Q046vXodehieGaNsA@mail.gmail.com> |
unsubscribe On Thu, 5 Feb 2026 at 23:11, Marc Chantreux <[email protected]> wrote: > Hello porters, > > I would like to improve a module and have the feeling there is nothing > I can do in pure perl so I post here to get advices. I apologize if > I missused the list: please let me know. > > Thanks for any help and regards. > Marc > > __DATA__ > > I discovered [haskell](https://fr.wikipedia.org/wiki/Haskell) in the > mid 2000 but never had the chance to put it at work. I wanted to > get the similar logic in Perl so I wrote https://metacpan.org/pod/Perlude, > presented it at French Perl Workshop ('10?) and YAPC::Europe'11. > > Book and Dolmen helped me to polish the thing and experimented a lazy > version of Perlude (which is only "on demand", like unix pipes) then it > remains untouched for many years. I tought I was the last one to use it but > I noticed someone made a debian package out of it. > > This module was good enough for me to use it without feeling the need to > improve it since then but now I have larger and larger datasets the > known performance issue of perlude hurts. This issue is known and > I declared I was unable to fix it at the time because Perlude is > based on anonymous subroutines returning scalars in an list context (so > the end of a stream is () which is a very functionnal programming > thing). I don't know how to mesure what costs the most. I remember I > tried to use some profilers but I was unable to understand the result > because everything happened in __ANON__ (AFAIR). > > Since then I discovered C and try to give XS a chance (also because I > would like to bind some fortran libraries at some point) so I would like > to investigate the only 3 anoying things I have with Perlude and I > wonder if XS could be a solution (as I found none in PP): > > 1. make it faster at execution > 2. make it even faster/easy to write with expressions instead blocks > with filter/apply (which are "on demand" conterparts of grep/map). > 3. put a value back to the stream in case of failure > > eg. > > use Perlude; > sub fibo { > my @seed = @_; > sub { > push @seed, $seed[0] + $seed[1]; > shift @seed; > } > } > my $fib = fibo 1, 1; > print join ",", fold takeWhile {$_ < 50} $fib; > print " then ...", $fib->(); > > problem 3: > > # fibo: 1,1,2,3,5,8,13,21,34,55,89 > # current output > # 1,1,2,3,5,8,13,21,34 then ...89 > # ideal output > # 1,1,2,3,5,8,13,21,34 then ...55 > > problem 2: > > current version: > > # with expressions intead blocks > print join ",", fold takeWhile {$_ < 50} $fib; > > # I wonder if there is a trick to make fold useless > print join ",", fold takeWhile $_ < 50, $fib; > > # or overload an operator for subroutines to fold > print join ",", @< takeWhile $_ < 50, $fib; > > -- > Marc Chantreux > Pôle CESAR (Calcul et services avancés à la recherche) > Université de Strasbourg > ☎ 03.68.85.60.79 >