Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34751 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72160 invoked by uid 1010); 11 Jan 2008 19:57:22 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 72145 invoked from network); 11 Jan 2008 19:57:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jan 2008 19:57:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=Kannan@facebook.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=Kannan@facebook.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain facebook.com designates 204.15.23.140 as permitted sender) X-PHP-List-Original-Sender: Kannan@facebook.com X-Host-Fingerprint: 204.15.23.140 fw-sf2p.facebook.com Windows 2000 SP4, XP SP1 Received: from [204.15.23.140] ([204.15.23.140:27682] helo=sf2pmxf02.TheFacebook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F0/A0-09267-02AC7874 for ; Fri, 11 Jan 2008 14:57:21 -0500 Received: from SF2PMXB01.TheFacebook.com ([192.168.16.15]) by sf2pmxf02.TheFacebook.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 11 Jan 2008 11:58:05 -0800 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Date: Fri, 11 Jan 2008 11:58:40 -0800 Message-ID: <300A9932AE9C0145A146B5A4E5CCE96901921FDD@sf2pmxb01.thefacebook.com> In-Reply-To: <6F71915A9839C8439C82524499A9B539148113B8@sf2pmxb01.thefacebook.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PHP-DEV] php-5.2.3: zend_opcode.c: pass_two() question Thread-Index: AchT4ZmYy5CpBNS3T8GcO9WScZ6tFAAAR1mAAAEAljAAKLVGcA== References: <300A9932AE9C0145A146B5A4E5CCE96901921EDC@sf2pmxb01.thefacebook.com> <698DE66518E7CA45812BD18E807866CE011C7C78@us-ex1.zend.net> <6F71915A9839C8439C82524499A9B539148113B8@sf2pmxb01.thefacebook.com> To: "Andi Gutmans" , X-OriginalArrivalTime: 11 Jan 2008 19:58:05.0804 (UTC) FILETIME=[47DF72C0:01C8548C] Subject: RE: [PHP-DEV] php-5.2.3: zend_opcode.c: pass_two() question From: Kannan@facebook.com ("Kannan Muthukkaruppan") I found the issue that was tripping me with the optimization I was attempting in #1.=20 Basically, there seem to be cases where "op_arrays" get destroyed during middle of program execution (e.g., op_array corresponding to the live code in a file seems to get destroyed at the end of the "include" operation; and I guess even the op_arrays corresponding to EVAL operations have the same property). Since "destroy_op_array()" frees the IS_CONST operands unconditionally (i.e. with ref count checking), with the attempted optimization, one can end up with pointers into freed data. The following simple test reproduced the issue: a.php: ------=20 While I did get some performance benefit with this simply by having less opcodes & thus less overhead in the interpreter loop, I had actually hoped to see more. Upon investigation, I realized that I hadn't really avoided the copy (due to the "is_ref=3D1" on the IS_CONST operand). And that's the reason for posting the question in this thread. =20 Since PHP disallows array literals in the context of "define" & "class constants", it seems to be a common programmatic idiom to assign array literals (such as list of application error messages, or a map of product ids to name, etc.) to a global variable and refer to the array everywhere in the program using that global variable. But then, there is a per-request penalty associated with building/tearing down such globals that are really just pointing to "read-only" data. This overhead would go away if assignments from an IS_CONST operand to a target didn't perform copies. Regards, Kannan -----Original Message----- From: Andi Gutmans [mailto:andi@zend.com] Sent: Thursday, January 10, 2008 3:46 PM To: Kannan Muthukkaruppan; internals@lists.php.net Subject: RE: [PHP-DEV] php-5.2.3: zend_opcode.c: pass_two() question Op arrays are read-only. This is a design goal and is especially important for byte code caches where several processes are looking at the same op array. Therefore setting IS_CONST to is_ref=3D1/refcount=3D2 = we are ensuring that they will not be changed. The copy happens only the first time and afterwards that zval may be used, incremented, etc... Net net, it is intended behavior and very important. Andi > -----Original Message----- > From: Kannan Muthukkaruppan [mailto:Kannan@facebook.com] > Sent: Thursday, January 10, 2008 3:36 PM > To: internals@lists.php.net > Subject: [PHP-DEV] php-5.2.3: zend_opcode.c: pass_two() question >=20 > An example assignment such as: > $x =3D 10; > doesn't seem to get handled as a simple ref-count incrementing=20 > assignment (in zend_assign_to_variable()). Instead, $x ends up getting > a new "zval" into which a copy of the RHS (10) is made. >=20 > This seems to be because the zval/znode corresponding to the literal 10 > is an IS_CONST operand of the assignment opcode. And, during the end=20 > of compilation of a function, the IS_CONST operands in the function's=20 > op_array are patched up as "references" (is_ref is set to 1). >=20 > zend_opcode.c:pass_two() > ... > while (opline < end) { > if (opline->op1.op_type =3D=3D IS_CONST) { > opline->op1.u.constant.is_ref =3D 1; > opline->op1.u.constant.refcount =3D 2; /* Make sure is_ref won't be = > reset */ > } > if (opline->op2.op_type =3D=3D IS_CONST) { > opline->op2.u.constant.is_ref =3D 1; > opline->op2.u.constant.refcount =3D 2; > } > ... >=20 > And zend_assign_to_variable(), when it sees the RHS to be a reference=20 > ("is_ref =3D=3D 1") ends up doing a copy rather than a ref-count=20 > incrementing assignment. >=20 > It seems like performance would be better if we didn't mark constant=20 > operands as "references" in pass_two(). But presumably it is required=20 > to handle some cases that'll otherwise break? I am trying to=20 > understand what those cases are. If someone can shed further light on > this issue, > it is much appreciated... >=20 > regards, > Kannan Muthukkaruppan