Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^7: What perl operations will consume C stack space?

by hv (Prior)
on Feb 27, 2006 at 18:53 UTC ( [id://533114]=note: print w/replies, xml ) Need Help??


in reply to Re^6: What perl operations will consume C stack space?
in thread What perl operations will consume C stack space?

The intention is to remove the C-stack recursion altogether and use perl's dynamic stacks instead. But that involves quite major surgery to the regexp engine, and I don't know when it is likely to happen.

It does make me wonder whether repetition counts, at least in these fairly simple cases, couldn't be fulfilled with by a tail recursive routine to alleviate the stack growth?

I don't know how you'd implement it to be tail recursive, but feel free to have a go. I suspect you'd need a quite different matching algorithm, in which case you'd probably end up needing rather more surgery than the current plan.

If not, isn't there some scope for putting a check of the form die 'Not enough stack' if reps > stacksize / 792?

As far as I know the stacksize isn't available within the perl process at the moment (nor more relevantly the current free stack space), and the cost per iteration may go up or down (depending on the build). If those numbers can be made available then yes, it would be a good idea to put a check in, probably by treating REG_INFTY as min(32766, freestack/stackcost).

Hugo

Replies are listed 'Best First'.
Re^8: What perl operations will consume C stack space?
by BrowserUk (Patriarch) on Feb 27, 2006 at 20:43 UTC

    Okay, i was just thinking out loud. You know I won't offering any patches to the regex engine any time soon :)

    It's quite easy to find out the base address and extent of the stack segment on x86, which combined with the current value of SP gets part of the equations. That's probably not true on all platforms though.

    For simple, self recursive routines I've calculated the stack requirement of the routine at runtime by subtracting the address of the first auto from the last + a fudge factor for parameters & return address, but it means putting all autos at the top of the routine. Trying to apply that technique to mutually recursive functions get tricky, and for functions the size and complexity of S_regmatch() it's non-starter.

    Everytime I look at subs that are basically one huge switch statement, I wonder of they couldn't be refactored into one of those GCC computed gotos that Parrot uses in one of it's dispatch loop varients.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://533114]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-24 00:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found