Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44167 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37001 invoked from network); 5 Jun 2009 00:15:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jun 2009 00:15:25 -0000 Received: from [127.0.0.1] ([127.0.0.1:22764]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 15/27-44672-D93682A4 for ; Thu, 04 Jun 2009 20:15:25 -0400 Authentication-Results: pb1.pair.com header.from=grahamk@facebook.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=grahamk@facebook.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain facebook.com designates 69.63.179.25 as permitted sender) X-PHP-List-Original-Sender: grahamk@facebook.com X-Host-Fingerprint: 69.63.179.25 mailout-snc1.facebook.com Linux 2.5 (sometimes 2.4) (4) Received: from [69.63.179.25] ([69.63.179.25:59398] helo=mailout-snc1.facebook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BB/17-44672-BE1682A4 for ; Thu, 04 Jun 2009 20:08:13 -0400 Received: from mail.thefacebook.com (intlb01.snat.snc1.facebook.com [10.128.203.15] (may be forged)) by pp01.snc1.tfbnw.net (8.14.1/8.14.1) with ESMTP id n55083sv024822 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT); Thu, 4 Jun 2009 17:08:06 -0700 Received: from SC-MBXC1.TheFacebook.com ([192.168.18.102]) by sc-hub02.TheFacebook.com ([192.168.18.105]) with mapi; Thu, 4 Jun 2009 17:08:06 -0700 To: Paul Biggar CC: PHP Internals , Brian Shire Date: Thu, 4 Jun 2009 17:08:05 -0700 Thread-Topic: Optimizer discussion Thread-Index: Acnlax5Gbo3l4XuaRZ2VZT8TjtvpwAAAjNYu Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=1.12.8161:2.4.5,1.2.40,4.0.166 definitions=2009-06-04_14:2009-06-01,2009-06-04,2009-06-04 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx engine=5.0.0-0811170000 definitions=main-0906040213 Subject: RE: Optimizer discussion From: grahamk@facebook.com (Graham Kelly) Hey, I always love having input. When you said it was vicious I was expecting mo= re, in fact I agree completely with you on a lot of things :-) Anyway, I'm not really sure how much detail you want me to go into (or how = much detail people on internals really want me to get into). So, I'll keep = it brief for now and can expand on anything. Why not start off with the big stuff, dataflow. I personally believe that w= orking out good data flow for PHP is key to getting good optimizations. But= you are right, its a very tricky thing to do and in some cases impossible.= Ultimately, I would like to move a lot of the optimizer work more into thi= s direction and use the data flow to build a basic platform for code analys= is on which optimizations can be done. For now though, pecl/optimizer is "d= umb" about data types :-) The reimplementations of some engine code is messy and work should probably= be done to try to remove this where possible. Also, I might be mistaken bu= t the is_numeric_result stuff is partly left over from Turck MMCache which = to my understanding this version of pecl/optimizer was based off of. Some o= f the stuff I was doing with building a function table (for optimizable and= some non optimizable functions) was to try and get rid of rudimentary data= type detection like this. Actually folding in values from function calls = is happening over in the optimize_fcr.c file. I 100% agree with you on the file system functions. They were in there when= I started working on the optimizer and I havent really paid much attention= to them. The latest CVS version of pecl/optimizer has them at least remove= d from being candidates for optimization (the code to actually optimize is = still there). I'm not sure which optimization you are talking about with the GLOBALS stuf= f but what your saying makes sense. (Its been awhile since I've looked at t= he code base myself, I'm just getting back to working on it) As far as my future plans for pecl/optimizer I should really gather up all = my ideas and stuff in the next week or so that you or anyone else who is in= terested can give feedback. At the moment, I'm working on getting the curre= nt version to a stable state. I'm also still trying to gauge demand for pec= l/optimizer to maybe help figure out direction for the project. (or if ther= e is really any real interest/or use). ________________________________________ From: Paul Biggar [paul.biggar@gmail.com] Sent: Thursday, June 04, 2009 4:20 PM To: Graham Kelly Cc: PHP Internals; Brian Shire Subject: Optimizer discussion Graham and I are having a brief chat about the work he's going to do on the PECL optimizer. People have asked me to do this on-list (they may have meant the PECL list, but optimizations on PHP seem more relevant here), so here goes. Hi Graham, So the general gist of what I have to say is that dataflow optimizations on PHP are very difficult, and nearly impossible at the function-local level. Loop-invariant hoisting and other redundant expression computation liekwise. If you're planning on working on them, we can go into more detail. I guess the biggest thing is that I'm wondering what your plans are for the PECL optimizer? I've spent about 2 years working on the phc optimizer, (and a bit longer on relevant things) so I hope that my advice will be relevant. I've taken a look through the optimizer a few times over the last while, (and even stolen some ideas from it). Here are my comments on the current code: - There is lots of code which reimplements parts of the engine, for example: ini_bool_decode, optimizer_acosh and friends, optimize_md5, optimize_crc32, optimize_sha1, optimize_class_exists and friends (to a lesser extent). There are also lots of constant foldings, like casts and "0 =3D=3D false" (etc) in optimize_code_block. I don't understand why there is logic in the code for that, rather than simply executing the opcodes, or constructing an eval and executing that. - is_numeric_result: there has been great effort to figure out numeric results from pure functions, when it seems straightforward to optimizer the results straight in. Maybe that is being done elsewhere? If so, there may need to be some care taken to ensure that all optimizations terminate. - File system functions are very iffy. I would be surprised if people have content that reads from files repeatedly, but where the files do not change, and who are willing to use that flag. - Most of the identity optimizations arent safe. $x + 0 !=3D=3D $x, unfortunately, due to integer coercions (parallels exist for other types/operators) - I think I saw an optimizations converting ("45" + $x) into (45+$x) - that's a great idea, which I will steal. - How does runkit (and other weird extensions) affect optimizations on constants, class_exists, etc? - The optimization "unsafe: optimize out isset()/empty() ops on GLOBALS['foo'] into $foo " is not safe, as GLOBALS['foo'] may not be the same variable as $foo ($GLOBALS may be unset, and indeed, there may be good reasons to do so). I'm also wondering what the optimizations are on fcall? I couldn't make it = out. That's quite a lot, but its everything I have on the current PECL optimizer= :) Thanks, Paul -- Paul Biggar paul.biggar@gmail.com