Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70459 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3562 invoked from network); 1 Dec 2013 00:30:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Dec 2013 00:30:27 -0000 Authentication-Results: pb1.pair.com header.from=ellison.terry@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ellison.terry@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.47 as permitted sender) X-PHP-List-Original-Sender: ellison.terry@gmail.com X-Host-Fingerprint: 74.125.82.47 mail-wg0-f47.google.com Received: from [74.125.82.47] ([74.125.82.47:39510] helo=mail-wg0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/A4-03478-1238A925 for ; Sat, 30 Nov 2013 19:30:25 -0500 Received: by mail-wg0-f47.google.com with SMTP id n12so9325296wgh.2 for ; Sat, 30 Nov 2013 16:30:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=5V/Vh/Jv7vL7+5XvB+a6+lbitMN/UKvcKG5nzVktGvw=; b=kiAFCYtOHXnexvsLTNgED2dmpSEqTwqQm2czCI+1WpVcmFXfKsgcTAK4mO7OWMB6Np yX/MpdjpOIDgJv59vNQkr/3KrGrLnlYi6CeNX5ODIk7JVO+g6fnQ90RiDj26pbcZRUgq uGiK4HC7MG79XHVJH3B7VGH86aeS0VrcjWfOBl7GjKOxVD2M10ClXitGx8hA0UcP+l8X cmVykco3GFFB1acgQuRdfjKRqDL4mgMESe3Zvizguji3QX1IG4UIK1M9fO3+4abIpT/u USLv4CpbnZsGC2BdU01dI2m9XZ3hKd9c2BnFATJ4uW5ZEuQiAznKCxyYD8xvtulug53/ pOyA== X-Received: by 10.180.160.239 with SMTP id xn15mr12267236wib.17.1385857821946; Sat, 30 Nov 2013 16:30:21 -0800 (PST) Received: from [192.168.1.91] (host81-152-194-204.range81-152.btcentralplus.com. [81.152.194.204]) by mx.google.com with ESMTPSA id dn2sm106568246wid.1.2013.11.30.16.30.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 30 Nov 2013 16:30:21 -0800 (PST) Message-ID: <529A831C.80401@gmail.com> Date: Sun, 01 Dec 2013 00:30:20 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: Stas Malyshev , PHP Internals References: <528CE64A.1020303@gmail.com> <528EA006.2090400@gmail.com> <52993190.4010905@gmail.com> <52995F97.7000901@sugarcrm.com> <5299B124.3030809@gmail.com> <529A5947.5060701@sugarcrm.com> In-Reply-To: <529A5947.5060701@sugarcrm.com> Content-Type: multipart/alternative; boundary="------------050803030102060504010301" Subject: Re: [PHP-DEV] Comments on non-unique naming convention for closures From: ellison.terry@gmail.com (Terry Ellison) --------------050803030102060504010301 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 30/11/13 21:31, Stas Malyshev wrote: >> 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, I will expand in this further in a separate thread. >> 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). Unfortunately this is not correct for closures. The current code for closures overwrites the previous function silently -- that is without error. OPcache has a different behaviour for a cached closure and instead ignores the new function (again silently) leading to a different behaviour for compiled scripts executed out of the opcode cache. See https://bugs.php.net/bug.php?id=64291 for PHPTs which demonstrate this failure. > 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. Filename/lineno is not unique as the PHPT shows. Use of counter can be flawed due to race conditions if OPcaching is enabled. This failure can occur in real app frameworks e.g. those which use a common compiler routine to generate custom templates. >> 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. +1 on avoiding time-related system calls -- even though these are pretty optimized on current Linux kernels -- however this is why we suggested a content based hash. Any alternatives that I can think of require a materially larger larger patch involving more source changes. Regards Terry --------------050803030102060504010301--