Re: Comments on non-unique naming convention for closures
| From: | Stas Malyshev | Date: | Sat, 30 Nov 2013 21:31:51 +0000 |
| Subject: | Re: Comments on non-unique naming convention for closures | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70458@lists.php.net to get a copy of this message | ||
Hi!
> The mangled zend_function entry is never executed; only used as a copy
> template.
I see. That makes it better, but not completely, please see below.
> This is really a separate thread, but in order to allow opcode caching,
> the PHP compiler *must* generate the same oparray for a given source
> sequence, so in fact even if the same function (...) {...} text sequence
> occured multiple times in the same source file, then the oparrays would
> be identical anyway, and using the same mangled zend_function entry is
> fine. However, if the 1/2^64 (or thereabouts) chance of a false
This is true. However, if multiple scripts have the same function name,
and are added to the cache separately in different time, by default the
engine does not allow adding the same function twice (even if it has the
same op-array). We could code around it but why create problems for
ourselves if we could easily avoid it? So I think it would be better to
add something to the mix - like filename/lineno or counter - to ensure
it is not the same. I'm not worried about the hash collisions, but
copy-paste happens much more frequent than 1/2^64 hash collision.
> collision is unacceptable, we could always embed the closure compile
> count in the name as well, or the microsecond compile time.
I would avoid using time, as getting time is usually a system call and
system calls are slow. Counter or filename/lineno or anything that makes
the hash different would be fine.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227