Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92066 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82869 invoked from network); 1 Apr 2016 19:49:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Apr 2016 19:49:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 157.56.111.107 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 157.56.111.107 mail-bn1bbn0107.outbound.protection.outlook.com Received: from [157.56.111.107] ([157.56.111.107:26944] helo=na01-bn1-obe.outbound.protection.outlook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9F/94-42107-4B0DEF65 for ; Fri, 01 Apr 2016 14:49:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=RWSoftware.onmicrosoft.com; s=selector1-zend-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=zkZg/wpaZ8OLlMvch3nPeXLmxZ3YIkrjqMu18Ro2biA=; b=GHH5x3o29GRxyty4+THP7pymlZKxC/9HVJLmKa0/gEhuBryGbXLRo4j7IcFt1MgWEEAjEm6SGbNmvHbDm3+tp8mEOQMbwPFRVSATbASL/UlXmDFQQHBjck4SCc6fl/LLUBvAg9x33HuuyeD+8MGGhabIWuBJLbWouPFIr2Kulnw= Received: from BY2PR0201MB1784.namprd02.prod.outlook.com (10.163.72.26) by BY2PR0201MB1783.namprd02.prod.outlook.com (10.163.72.25) with Microsoft SMTP Server (TLS) id 15.1.447.15; Fri, 1 Apr 2016 19:49:05 +0000 Received: from BY2PR0201MB1784.namprd02.prod.outlook.com ([10.163.72.26]) by BY2PR0201MB1784.namprd02.prod.outlook.com ([10.163.72.26]) with mapi id 15.01.0447.026; Fri, 1 Apr 2016 19:49:05 +0000 To: Lin Yo-An CC: internals , Xinchen Hui , Nikita Popov Thread-Topic: [PHP-DEV] Object getter method optimization Thread-Index: AQHRi/GHRF/zIxahgUWBXeSuU8QB2Z91QfoAgAAJVQCAADi/RQ== Date: Fri, 1 Apr 2016 19:49:04 +0000 Message-ID: References: , In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: lists.php.net; dkim=none (message not signed) header.d=none;lists.php.net; dmarc=none action=none header.from=zend.com; x-originating-ip: [132.245.81.165] x-ms-office365-filtering-correlation-id: 462b3ba3-b105-48b7-d5f8-08d35a66aed4 x-microsoft-exchange-diagnostics: 1;BY2PR0201MB1783;5:Vzm5Dh9VcrvpKse0/9z00udKFQjYTYx2hJgcqcIqwCi2CrFt0vTK22ZEGkK66ikiavyyYQ/9H8HUVjK0SATCGrfhdzE2jEFNj5gGOQTuYZmkQf1h0N+ZARgVqEDLi+cWOdo0XG+35F/mdo+H8qOWFA==;24:MnD6hXJTkAMRzURH5qiYANBvFVVK7hlNN3GBUNe6AH300pAwgQeHiB1dkZB69zZ3PdJTWRNNHsXAl64M71c+gB6uC2eAMByzJpE29KNoKhk= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0201MB1783; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046);SRVR:BY2PR0201MB1783;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0201MB1783; x-forefront-prvs: 0899B47777 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(164054003)(377454003)(24454002)(53754006)(5004730100002)(81166005)(19617315012)(2900100001)(106116001)(2950100001)(586003)(99286002)(19627405001)(86362001)(74316001)(110136002)(76176999)(102836003)(3846002)(50986999)(189998001)(54356999)(11100500001)(10400500002)(16236675004)(5008740100001)(15975445007)(77096005)(6116002)(1096002)(19625215002)(87936001)(1220700001)(3280700002)(3660700001)(5002640100001)(122556002)(3900700001)(76576001)(4326007)(5003600100002)(66066001)(19580405001)(19580395003)(2906002)(16799955002)(92566002);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR0201MB1783;H:BY2PR0201MB1784.namprd02.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: multipart/alternative; boundary="_000_BY2PR0201MB1784EBD54B1E4B46590A1670BF9A0BY2PR0201MB1784_" MIME-Version: 1.0 X-OriginatorOrg: zend.com X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Apr 2016 19:49:04.9313 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 32210298-c08b-4829-8097-6b12c025a892 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0201MB1783 Subject: Re: [PHP-DEV] Object getter method optimization From: dmitry@zend.com (Dmitry Stogov) --_000_BY2PR0201MB1784EBD54B1E4B46590A1670BF9A0BY2PR0201MB1784_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable HI Yo-An Lin, I added comments to PR. After fixing obvious errors (explained in comments), few tests are still fa= iled tests/classes/unset_properties.phpt Zend/tests/bug52614.phpt The introduced run-time check in ZEND_INIT_METHOD_CALL speed-ups getters in= cost of small overhead for all other methods. I don't see any visible performance change on real-life apps. Thanks. Dmitry. ________________________________ From: Lin Yo-An Sent: Friday, April 1, 2016 19:14 To: Dmitry Stogov Cc: internals; Xinchen Hui; Nikita Popov Subject: Re: [PHP-DEV] Object getter method optimization I submitted my PR here https://github.com/php/php-src/pull/1847 On Fri, Apr 1, 2016 at 11:41 PM, Lin Yo-An > wrote: Hi internals, Here comes the result: Without getter optimization (3 runs): 250.76603889465ms With getter optimization (3 runs) 110.88299751282ms Microbench result: https://gist.github.com/c9s/0273ac21631562724cabf86c42e8= 6e32 On Fri, Apr 1, 2016 at 4:35 PM, Lin Yo-An > wrote: Hi Dmitry, Nikita, Andrea My implementation now is able to get the property offset and fetch object p= roperty directly without invoking zend_std_read_property and pushing new ca= ll frame onto the stack. The current behavior: 1. In compile-time, the pass_two() function now marks the getter functions = in op_array.accessor.type 2. When Zend Engine first time attempt to read the property, it saves the p= roperty offset in the accessor field and mark the method as a "getter". 3. When Zend Engine second time invoke the getter method, it checks the acc= essor field and try to read the property value directly instead a "method c= all" The implementation did some change: 1. Added accessor struct to op_array to save "accessor" related information= (getter or setter, property offset) 2. Added two statement in zend_std_read_property to save property offset. 3. Added op code check in zend_compile (The pass_two() function) to mark a = function is a getter) But now I encountered a problem, I can't store the result value in INIT_MET= HOD_CALL op, the result var is only available in DO_FCALL_* I have an idea for solving this, but I'm not sure if it's good or not: If DO_FCALL_* will always follow a INIT_METHOD_CALL, then I think we can st= ore result var from the next op (DO_FCALL) and skip DO_FCALL directly. Would be great if I can have your advices and suggestion. :-) Thanks, Yo-An Lin On Tue, Mar 22, 2016 at 4:45 PM, Dmitry Stogov > wrote: Hi Yo-An Lin, This "run-time inlining" approach may work. PHP compiler (or optimizer) may mark functions and methods suitable for "ru= n-time" inlining (e.g. methods without arguments and FETCH_OBJ_R UNUSED, CO= NST -> TMP; RETURN TMP). Then INIT_METHOD_CALL may check this flag and execute "optimized code seque= nce" instead of pushing stack frame and real call. However, I'm not sure what kind of performance impact this may make, becaus= e we will have to make additional check on each INIT_METHOD_CALL execution. Thanks. Dmitry. ________________________________ From: Lin Yo-An > Sent: Saturday, March 19, 2016 10:08 To: Dmitry Stogov Cc: internals; Xinchen Hui Subject: Re: [PHP-DEV] Object getter method optimization Hi Dmitry, Thanks for your reply! You're correct. let me try to explain your points: If I have a main.php and worker.php And I defined work($worker) { $status =3D $worker->getStatus(); } inside ma= in.php when main.php is compiled, we don't know what the class entry of $worker is= . What we only know is invoking a method "getStatus" on $worker CV unless w= e know we have to compile worker.php before main.php and add a type hint on= $worker. Is it correct? Since the original approach doesn't work, here comes another new idea: When executing method call on an object, if we found the method body are ju= st 2 op codes (FETCH_OBJ_R and RETURN), we then denote the method is a "get= ter method" And the next time, when we execute the same method, we found the "getter me= thod" flag, we simply execute FETCH_OBJ_R on that object and return the val= ue to avoid extra op code execution time. Do you think if this could work? Best Regards and Thanks for your work on PHP VM Yo-An Lin On Fri, Mar 18, 2016 at 3:36 PM, Dmitry Stogov > wrote: Hi Yo-An Lin, Unfortunately, this approach won't work. At first, at compile time we don't know the body of called getter. At second, the called method might be changed even at run-time, because of = polymorphism. Tricks like this might be implemented using JIT and polymorphic inline cach= es. Thanks. Dmitry. ________________________________________ From: Lin Yo-An > Sent: Friday, March 18, 2016 05:23 To: internals Subject: [PHP-DEV] Object getter method optimization Hello Everyone, I am recently trying to write an optimizer that could optimize the getter method call into just one object fetch opcode. I'd like to know thoughts from you guys, here is the note: https://c9s.hackpad.com/INLINE-OP-TVGo9WcshbZ -- Best Regards, Yo-An Lin https://github.com/c9s -- Best Regards, Yo-An Lin -- Best Regards, Yo-An Lin -- Best Regards, Yo-An Lin -- Best Regards, Yo-An Lin --_000_BY2PR0201MB1784EBD54B1E4B46590A1670BF9A0BY2PR0201MB1784_--