RE: [PHP] performance issues
On 17 April 2008 11:57, Bojan Tesanovic advised: in PHP5 by default Objects are passed by reference Please stop repeating this -- erm -- inexactitude. In PHP5, objects are passed around by their handle, *not* as a reference. Most of the time, this has the same effect, as you are addressing the same object either way. However, the behaviour of a copied object handle is not the same as a reference. In fact, when you create a reference to an object, what you're actually getting is a reference to the object's handle! To prove this, try running the test code below -- the object handling will not, I assure you, behave as though you were passing a reference around by default, but is directly comparable to the following string example: ?php class test { public $me; } $t = new test; $t-me = 'Original'; $copy_t = $t; $ref_t = $t; $copy_t = new test; $copy_t-me = 'Altered Copy'; echo RESULT1 Original: $t-mebr / Copy: $copy_t-mebr / Reference: $ref_t-mebr / RESULT1; $ref_t = new test; $ref_t-me = 'Altered Reference'; echo RESULT2 br / Original: $t-mebr / Copy: $copy_t-mebr / Reference: $ref_t-mebr / RESULT2; $s = 'String'; $copy_s = $s; $ref_s = $s; $copy_s = 'String Copy'; echo RESULT3 br / Original: $sbr / Copy: $copy_sbr / Reference: $ref_sbr / RESULT3; $ref_s = 'String Reference'; echo RESULT4 br / Original: $sbr / Copy: $copy_sbr / Reference: $ref_sbr / RESULT4; ? Cheers! -- Mike Ford, Electronic Information Services Adviser, JG125, The Headingley Library, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 812 4730 Fax: +44 113 812 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance issues
On Wed, 2008-04-16 at 23:37 -0400, Nathan Nobbe wrote: all, i have heard from various sources that using the in php can at times be costly, and therefore, it should not be used when it is not needed. for example, passing an array by reference because you think youre passing the actual array is not a good idea. only pass it by reference if a modified version needs to be handed to the calling code via an actual parameter. im also wondering about php4 code thats now running under 5; such as function returnObject() ... $a = new SomeClass() ... lets suppose, for the sake of arguments, i have my hands on a codebase where everything actually does count. the code was php4 and is now transitioning to 5. does anybody know if there would be a performance gain in running the whole thing through sed to try and strip out the unnecessary characters ? any empirical data? If it's faster, it's faster so that would suggest a performance gain... but as many will tell you, and you most likely already know... is the gain worth the effort? BTW, rote replacement of references like that, may not be a good idea. There are times when you really do want a reference to an object... or maybe not... but you or someone else might have done it anyways ;) Contrast: ?php $b = new Foo(); $a = $b; $a = new Fee(); ? Versus: ?php $b = new Foo(); $a = $b; $a new Fee(); ? In the first $b references the instance of Fee since $a is a reference. In the second, $b remains an instance of Foo when $a becomes and instance of Fee. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance issues
On Apr 17, 2008, at 5:37 AM, Nathan Nobbe wrote: all, i have heard from various sources that using the in php can at times be costly, and therefore, it should not be used when it is not needed. for example, passing an array by reference because you think youre passing the actual array is not a good idea. only pass it by reference if a modified version needs to be handed to the calling code via an actual parameter. im also wondering about php4 code thats now running under 5; such as function returnObject() ... $a = new SomeClass() ... lets suppose, for the sake of arguments, i have my hands on a codebase where everything actually does count. the code was php4 and is now transitioning to 5. does anybody know if there would be a performance gain in running the whole thing through sed to try and strip out the unnecessary characters ? any empirical data? thx, -nathan in PHP5 by default Objects are passed by reference and as you can see at this graph passing array by reference in PHP5 is slower http://nathan.moxune.com/arrayVsArrayIteratorReport.php Bojan Tesanovic http://www.carster.us/
Re: [PHP] performance issues
On Thu, Apr 17, 2008 at 12:14 AM, Robert Cummings [EMAIL PROTECTED] wrote: If it's faster, it's faster so that would suggest a performance gain... but as many will tell you, and you most likely already know... is the gain worth the effort? BTW, rote replacement of references like that, may not be a good idea. There are times when you really do want a reference to an object... or maybe not... but you or someone else might have done it anyways ;) im not sure if its worth the effort yet; thats sortof why im asking about it on the list. obviously ill risk introduction bugs, which obviously, i dont want to do... ill have to analyze the regression system as it stands. if its decent, i might be able to use it as a benchmark utility and to test for bugs after the mass conversion. Contrast: ?php $b = new Foo(); $a = $b; $a = new Fee(); ? Versus: ?php $b = new Foo(); $a = $b; $a new Fee(); ? In the first $b references the instance of Fee since $a is a reference. In the second, $b remains an instance of Foo when $a becomes and instance of Fee. wow, thats a clever example. honestly, i dont think ive ever done that before myself... but clearly that doesnt mean others havent in this codebase. thanks for the insight. -nathan
Re: [PHP] performance issues
On Thu, Apr 17, 2008 at 4:57 AM, Bojan Tesanovic [EMAIL PROTECTED] wrote: in PHP5 by default Objects are passed by reference and as you can see at this graph passing array by reference in PHP5 is slower http://nathan.moxune.com/arrayVsArrayIteratorReport.php wow, thats hilarious, thats my own chart :O ROTFL im glad somebody else thought something of it ;) -nathan
Re: [PHP] performance issues
On Thu, Apr 17, 2008 at 12:00 PM, Nathan Nobbe [EMAIL PROTECTED] wrote: On Thu, Apr 17, 2008 at 4:57 AM, Bojan Tesanovic [EMAIL PROTECTED] wrote: in PHP5 by default Objects are passed by reference and as you can see at this graph passing array by reference in PHP5 is slower http://nathan.moxune.com/arrayVsArrayIteratorReport.php wow, thats hilarious, thats my own chart :O ROTFL im glad somebody else thought something of it ;) -nathan I almost spit my water out when I saw that link directed at you. Your work is famous! ;) I don't have an actual answer as far as benchmarks go. I've been converting all of my sites from php4 to 5 over the past 3 months stripping out 's as I go. I haven't noticed any differences myself though. But then again I've been adding in type hints and visibility too so I'm sure that isn't helping. I'm always pimping Xdebug, so just remember it will show you where your real bottlenecks are instead of guessing. *shrug* -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance issues
On Thu, Apr 17, 2008 at 11:51 AM, Eric Butera [EMAIL PROTECTED] wrote: On Thu, Apr 17, 2008 at 12:00 PM, Nathan Nobbe [EMAIL PROTECTED] wrote: On Thu, Apr 17, 2008 at 4:57 AM, Bojan Tesanovic [EMAIL PROTECTED] wrote: in PHP5 by default Objects are passed by reference and as you can see at this graph passing array by reference in PHP5 is slower http://nathan.moxune.com/arrayVsArrayIteratorReport.php wow, thats hilarious, thats my own chart :O ROTFL im glad somebody else thought something of it ;) -nathan I almost spit my water out when I saw that link directed at you. good times! Your work is famous! ;) well i do what i can :D I don't have an actual answer as far as benchmarks go. I've been converting all of my sites from php4 to 5 over the past 3 months stripping out 's as I go. I haven't noticed any differences myself though. But then again I've been adding in type hints and visibility too so I'm sure that isn't helping. yea; i hadnt thought of the overhead of adding visibility / type hinting in. but if im adding those, either way; the extra cost from the can be gained back if theyre yanked. I'm always pimping Xdebug, so just remember it will show you where your real bottlenecks are instead of guessing. *shrug* xdebug is da bomb; thats what i used to build the charts from the performance report ;) ok, so heres what im thinking. any functions that return by reference can safely be changed, right? so i could do a mass replace like this find: 'function ' replace: 'function ' note, there is a space after function in the replace. i think the only reason to use return by reference is when returning an object to avoid getting a copy back in the php4 days. the rest im thinking can be done by hand as time goes on. waddya all think? thx, -nathan
Re: [PHP] performance issues
On Thu, Apr 17, 2008 at 7:10 PM, Nathan Nobbe [EMAIL PROTECTED] wrote: On Thu, Apr 17, 2008 at 11:51 AM, Eric Butera [EMAIL PROTECTED] wrote: On Thu, Apr 17, 2008 at 12:00 PM, Nathan Nobbe [EMAIL PROTECTED] wrote: On Thu, Apr 17, 2008 at 4:57 AM, Bojan Tesanovic [EMAIL PROTECTED] wrote: in PHP5 by default Objects are passed by reference and as you can see at this graph passing array by reference in PHP5 is slower http://nathan.moxune.com/arrayVsArrayIteratorReport.php wow, thats hilarious, thats my own chart :O ROTFL im glad somebody else thought something of it ;) -nathan I almost spit my water out when I saw that link directed at you. good times! Your work is famous! ;) well i do what i can :D I don't have an actual answer as far as benchmarks go. I've been converting all of my sites from php4 to 5 over the past 3 months stripping out 's as I go. I haven't noticed any differences myself though. But then again I've been adding in type hints and visibility too so I'm sure that isn't helping. yea; i hadnt thought of the overhead of adding visibility / type hinting in. but if im adding those, either way; the extra cost from the can be gained back if theyre yanked. I'm always pimping Xdebug, so just remember it will show you where your real bottlenecks are instead of guessing. *shrug* xdebug is da bomb; thats what i used to build the charts from the performance report ;) ok, so heres what im thinking. any functions that return by reference can safely be changed, right? so i could do a mass replace like this find: 'function ' replace: 'function ' note, there is a space after function in the replace. i think the only reason to use return by reference is when returning an object to avoid getting a copy back in the php4 days. the rest im thinking can be done by hand as time goes on. waddya all think? thx, -nathan Should be ok, but that is what unit tests are for, right? ;) I only used return by reference when returning objects. I think referencing array inputs would be more of a challenge if there was any trickery going on there. The return value should just be a final here you go since the function is done at that point. Guess you'll find out when you try it. Just make a backup first! :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Performance issues and trees
Sven Riedel wrote: letters 0 and 1. My tree-traversal algorithm looks like this: $bit_array = str_split( $bitstring ); $tree_climber = $tree; // assign tree-climber to the tree root // main loop while( !is_null( $bit = array_shift( $bit_array ) ) ) { $tree_climber = $tree_climber[$bit]; // going down... if( !is_array( $tree_climber ) ) { // we reached a node process( $tree_climber ); $tree_climber = $tree;// and back up to the root we go } } I'm seeing execution times in excess of 30 seconds for a few hundred (~ 200 - 300 ) tree-runs (with the tree in question being of average depth 5, translating to 1000 - 1500 assignments, which is way to slow to be practical. And the main holdup _is_ the tree-traversal, the sum of the process() functions is in the range of 0.3 seconds (measured with microtime(true) ). Have you tried using a profiler on the code? APD might prove useful: http://pecl.php.net/package/apd This can show you exactly how much execution time is being spent in each function of your code, whether user-defined or built in, and can list average execution times per function, etc. Personally it's been several years since I've toyed with binary trees (my second semester of Pascal grin) and I can't tell for sure what's going on in what little code you posted. For example, I can't tell by what you posted if the array_shift() above is necessary. If you merely need to traverse $bit_array without actually modifying it then I suspect a simple foreach would be much faster, but I'm probably missing something... If you have the time and the inclination you may want to post a link to your actual working code... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance issues and trees
On Tue, Jul 20, 2004 at 09:49:07AM -0500, Michael Sims wrote: above is necessary. If you merely need to traverse $bit_array without actually modifying it then I suspect a simple foreach would be much faster, but I'm probably missing something... Ah, I just changed that and now it's a hundred-fold faster, thanks! Regs, Sven -- -Trigital- Sven Riedel . Tel: +49 511 1236364 . Fax: +49 511 1690746 . email: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance issues
1megabyte of code :) not 1M lines sorry about that confusion there and the problem began slow, not noticable... But it's now worse then ever. Jon Haworth [EMAIL PROTECTED] wrote in message 67DF9B67CEFAD4119E4200D0B720FA3F0241E995@BOOTROS">news:67DF9B67CEFAD4119E4200D0B720FA3F0241E995@BOOTROS... Hi Karel, mysql entries: at least 2M php code: at least 1M lines More than a million lines of code? That's a *big* app. And now we are experiencing a really heavy load on the server. (no root access, but we think it's PHP). You're running it on a server with no root access? Is it a shared server? If you're running a 1,000,000 LOC app I'd expect it to have enough traffic that a dedicated box would be a necessity. Have you looked at the output from top when the load is getting too heavy? This will tell you which processes are tying up the processor. Did the heavy load happen immediately after your code change? If so then that might be a culprit... are there any chunks of code you can roll back to the old version to see if the load decreasese? (e.g. have you modified a bit to use a *lot* of string concatenation, or something?) Cheers Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Performance issues
Hi Karel, mysql entries: at least 2M php code: at least 1M lines More than a million lines of code? That's a *big* app. 1megabyte of code :) not 1M lines Aha :-) and the problem began slow, not noticable... But it's now worse then ever. Are you doing something that degrades, like reading in an entire text file, adding a line to the end of it and saving it again? (Each time you do this it will take a bit longer). Did you look at the output from top (assuming unix) or task manager (assuming windows)? Cheers Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php