-----Original Message-----
From: Marcus Boerger [mailto:mail@marcus-boerger.de]
Sent: Friday, March 14, 2008 9:28 PM
To: Stas Malyshev
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] Patch for opcode cachesHello Stanislav,
Friday, March 14, 2008, 6:48:52 PM, you wrote:
Hi!
Lemme just think, doing inheritance at compile time before we send
the stuff to an opcode cache can be slower then? How is that
possible? After all late binding means we do it at run
time. And no
matter how much faster we can do it. It will always be slower than
doing the same thing only once.I'm taking this off-list because it doesn't seem to go any
direction
it
can be useful for people to read.Hmm, so other people must not read what we discuss, that does
not work.Repeating again: it can not be done "only once". Not with opcode
caches
present and bound entities living in separate file. This
thing is not
possible. If you do not believe it - try to implement it and see.That is my point. It can be done.
Look into the example:
parent1.php
<?php
class Foo {...}
?>
parent2.php
<?php
class Foo {...}
?>
child.php
<?php
class Bar extens Foo {...}
?>
index1.php
<?php
include "parent1.php";
include "child.php";
?>
index2.php
<?php
include "parent2.php";
include "child.php";
?>
Do you still think if early-binding for class Bar is possible at
compile-time with opcode caches?
And what "Foo" is the parent?
The reason to delay
inheritance is that we can have a conditional statement
around a class definition.
There is no "if' statement in example above.
Also detection of conditional code is additional pine for caches.
If we detect classes that do not
have conditionals around them, then we can bind them early.
It's wrong.
It is as easy as that. So instead of making the language more
dynamic and even removing a chance of having inheritance
dones early where possible we should work on making the
desired case - eraly binding - as easy as possible.
The proposed patch allows caches to implement proper behavior of
early-biniding in most easy way. (~5 lines of code)
Thanks. Dmitry.
session (or caused by TSRM/ZendEngine) seems broken in my local cvs
checkout i'm not sure if it's relatived to this patch but i did 'cvs
up' and some commit broke the patch (with conflicts)
please commit, or roll out another diff against the PHP_5_3 cvs so i
can test it again
thanks
The patch has been just committed.
You should use something like the following code to make it work.
function cache_compile_file($filename) {
if (!is_cached($filename)) {
...
orig_compiler_options = CG(compiler_optins);
CG(compiler_options) |=
ZEND_COMPILE_IGNORE_INTERNAL_CLASSES |
ZEND_COMPILE_DELAYED_BINDING;
$op_array = orig_compile_file($filename);
CG(compiler_options) = orig_copiler_options;
...
} else {
$op_array = restore_from_cache($filename);
}
zend_do_delayed_early_binding($op_array);
}
Thanks. Dmitry.
phpxcache wrote:
session (or caused by TSRM/ZendEngine) seems broken in my local cvs
checkout i'm not sure if it's relatived to this patch but i did 'cvs
up' and some commit broke the patch (with conflicts)
please commit, or roll out another diff against the PHP_5_3 cvs so i
can test it againthanks