At 10:16 PM 1/13/2004 -0700, Luke Palmer wrote:
David Storrs writes:
> Given this code:
>
>     if ( some_expensive_lookup_function() >= $MAX_RECORDS ) {
>        mark_that_we_have_reached_max_records();
>        return;
>     }
>
> After I enter that block once, I never want to evaluate the condition
> again--I want the code to completely disappear from the bytecode (or,
> at least, be jumped around).  How would I do that in Perl 6?

Hmm...

    my $max_reached;
    sub mark_that_we_have_reached_max_records() {
        $max_reached = 1;
    }

If you use a hint in Perl6 to tell Parrot that $max_reached needs to be a native type you'll probably get near C-speed conditional tests with the JIT. (The JIT is many x faster than current Perl5 conditionals, but the reason we don't rave about it more often is that languages like Perl6 lose a lot of what the JIT provides since we have to create most variables as PMCs)

I think Perl6 will allow a hint like so:

my int $max_reached;

The important thing is that $max_reached is used simply as a conditional,
and you don't pass it to a routine or otherwise use it in a way to cause it to be
promoted to a PMC (which is much heavier than a native). Currently the back-end
compiler (imcc) doesn't coerce native types to a PMC, but it will eventually.
If you use a hint, and simply set and test the conditional, the compiler should
be able to allocate the conditional as a pure integer register, test it, and skip the
PMC promotion.


Then your worry about getting the test removed from the bytecode would
be needless as you'd probably only waste a couple of JITed CPU cycles.

-Melvin




Reply via email to