At 9:40 PM +0200 7/19/04, Leopold Toetsch wrote:
Below [1] is a small test program, which basically shows the speed of
calling generators aka coroutines. But *what* I want to discuss isn't
restricted to calling coroutines. Its the same (more or less) with
calling any subroutine-like thingy, being it a method, an overriden
operator, or an internal method, like array.sort(), if the "optmizer"
doesn't know, what kind of method gets called, because e.g. the method
was passed in as function argument.

Leo, we've talked about this before. The sensible and straightforward thing to do in a case like this is to tag in the sub pmc which register frames are used by the sub. When a sub is invoked via C code, those frames and nothing else are saved. It takes 8 bits and some logical tests which can cut down on the allocating and copying by only noting which frames are actually touched.


If we have the *calling* sub tag the dirty frames we can cut down on it even more by only saving the frames that are touched and need saving. We could even save the explicit save/restore this way if we wanted to, if we allowed the call functions to update the continuations we pass in, leaving it up to the calling mechanism to determine what needs saving and what doesn't.

I'm not sure what you're thinking of with coroutines. Co-routines which yield out data (rather than returning and resetting) need to exit via a different mechanism (like, say, the *yield* op) which saves off the relevant current state in the current sub object.

All sub objects need to keep part of the interpreter structure cached in them. The context structure almost requires duplication, as do the opcode-related pointers and info (so each sub can have its own handle on what opcodes are in force) and some of the other things in there. (Which ought to be in the context structure anyway, honestly) Subs and the first invocation of a coroutine should have defaults in there, while the current data should be copied out into the backing store when a coroutine yields so it can be put right back again as it was left when the coroutine exited. The big difference between subs and coroutine PMCs is that subs only need one copy, while coroutines need two (A current and a default, with the default restored on normal exit) and that's arguably only needed in certain circumstances.
--
Dan


--------------------------------------it's like this-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to