home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


20.7 A Peek into the Future

In this section, I'll describe a few of the exciting things that we can look forward to, possibly in the next few major releases of Perl.

Multithreaded interpreter

Malcolm Beattie has released an early version of a thread-safe Perl interpreter based on POSIX threads. (Search for the "thrperl" in the Perl 5 Porters archive [ 4 ].) This modified interpreter is not thread-hot; that is, it does not use threads itself (unlike the Java environment, for example, which uses separate threads for updating the user interface and for garbage collection). It allows the user to create as many threads as required and provides support for standard thread primitives such as monitors and condition variables. As currently implemented, all global data structures introduced in this chapter have simply become per-thread entities. That is, each thread gets its own set of stacks, its own stashes, and thread-local variables such as errgv ( $@ ). Lexical variables are allocated out of subroutine and thread-specific scratchpads.

Static typing hints

Give hints to the interpreter for better optimization and type-checking. Larry's example, which has acquired near "hello world" status on the p5p list, is as follows:

    my Dog $spot = new Dog;

Now $spot is tagged at compile time as belonging to a class called Dog , so a call such as $spot->meow() will be a compile-time error, unless you have a mutant dog.

Faster objects

Expect better support for objects and a possible standard replacement for the ObjectTemplate module. You may be able to say something like this:

    package Dog;
    use Fields qw(breed color);
    $spot = new Dog;
    print $spot->{color};

What looks like a hash access in the last statement may in fact be optimized at compile-time to an array access, by replacing the attribute name with the field offset; that is, $spot->{color} becomes $spot->[1] .

Perl compiler

Malcolm has also submitted a Perl compiler extension [ 7 ], which is in its early stages as of this writing. It can be asked to translate a script to C code, which can be compiled to form an executable; as it happens, this executable is not much faster than the interpreted script, because most of the action still takes place in opcode functions as they exist now. Static typing hints may usher in some aggressive optimizations. For example, if you say:

     my integer $i;

the compiler would use C's native integer type, rather than an SV - this would speed up loops and arithmetic expressions.

The compiler can alternatively produce a byte-code file and have the interpreter eval it subsequently, similar to the facilities provided by Python and Java. It also supports much better debugging options than those currently provided with -D .