develooper Front page | perl.perl5.porters | Postings from March 2008

Re: faster safe signals?

Thread Previous | Thread Next
Nicholas Clark
March 21, 2008 17:48
Re: faster safe signals?
Message ID:
On Fri, Mar 21, 2008 at 09:32:19AM -0600, Jim Cromie wrote:
> ># 3 "PERL_ASYNC_CHECK expands to"
> >if ((my_perl->Isig_pending)) Perl_despatch_signals(my_perl)
> >
> >We do the check after every op. I wondered, if we did the check
> >
> >1: At every LOGOP (so every loop iteration)
> >  
> do it at nextstates ?
> and what about map/grep ?
>    in debugger at least, an 'n' will often stop many times at the same 
> map/grep op

mapwhile and grepwile are LOGOP. So they are already covered in 1.

nextstate might also be another good one.

> >2: At scope exit
> >3: At scope entry (or just subroutine entry, given 1 and 2)
> >4: Before sleep and select
> >  
> before or after system calls ?
>    that buries the check further down ( which may not be bad, just 
> different )
>    sounds like it would cover case 5 too

Possibly. But given that what I'm proposing is to add the check in a lot of
places, which will increase executable size and maintenance liability, there
is a trade off between number of places and coverage quality.

> theres also a context switch at systemcall, might as well do it then, 
> since caches are cold already
> >5: Before and after IO operations

These seemed like the most useful minimal set of (probably) syscalls to wrap,
simply because they are the most likely to block (and hence task switch) the
process. (Rather than merely the context switch of most syscalls)

> >6: (maybe also) every time the regexp engine backtracks
> >  
> Or particularly where regex recursion happens.
> I'll wager Yves can find a nice corner to hide this in.

The engine itself is no longer recursive in implementation. Right now, safe
signals aren't able to interrupt regexps. I was assuming that most "heat death
of the universe" regexps involve a lot of backtracking, so that seemed like
the compromise point between too many checks, and checks spread too far apart.
I was assuming that regexps that don't need to backtrack, however they match,
manage to match very quickly. (And return you to your regularly scheduled

Nicholas Clark

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About