develooper Front page | perl.perl6.internals | Postings from June 2001

Re: should vtables be vtables?

Thread Previous
From:
Bart Lateur
Date:
June 13, 2001 06:02
Subject:
Re: should vtables be vtables?
Message ID:
uooeit8532gdp85vtl3u57ce7odb42opm6@4ax.com
On Wed, 13 Jun 2001 12:00:21 +0100 (BST), Dave Mitchell wrote:

>I was thinking back to the earlier discusions on opcode dispatch,
>and the fact that some people thought that a big switch was as good as,
>or possibly faster than a dispatch table. Which led me to think...

I would think that a switch could be optimized by the compiler by
turning it into a jump table. That way, it's not surprising that it "can
be as fast". Un der the surface, it is the same thing!

>should we abandon vtables (ie arrays of fn pointers indexed by op),
>and just have a single hander function per type which has the op as an arg?

You mean, like Windows' "window function? Shudder.

I wouldn't do that. For one thing, a vtable can grow dynamically,
functions can be added at runtime. It doesn't matter, the machine code
to execute remains the same for built-in, or for freshly added
functions.

In a statically compiled switch, it is impossible to add a new function,
i.e. a new switch branch.

Furthermore, unoptimized switches are definitely slower than vtables.
Internally, a switch is turned into something like:

	if($fn == FN1) {
		...
	} elsif($fn == FN2) {
		...
	} elsif($fn == FN3) {
		...
	} elsif($fn == FN4) {
		...
	} elsif ...
	}

The further down the chain, the slower the dispatching. Do you really
want that?

-- 
	Bart.

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About