> > Have you explored Symfony's caching features yet? You can cache entire > pages, or cache the action without caching the layout (which makes it > easy to keep the logged-in-user aspects of the page dynamic), or even > cache individual components or partials. I've found the performance > benefits of these features to be so dramatic that optimizing the > daylights out of the low-level details of the code doesn't make much > sense, at least not when the optimized version is much less > maintainable and understandable than the original. > > Even a highly dynamic site can often take advantage of the cache by > setting the cache lifetime to something quite short, like five > minutes, for the generation of an otherwise expensive thing like a > richly detailed month-long calendar view (I do something like this at > salsadelphia.com). > > That doesn't address the extra whitespace in transmission issue of > course. My first thought was "there should be a low-level Apache > module that does that for you." But it turns out that development of > such a module was rejected because mod_gzip saves much more space. > Browser support for mod_gzip appears to be pretty well universal at > this point.
Indeed, zipping your site's responses is very efficient and supported in most browsers. The mod detects browser support automatically so it's basically a no-brainer turning it on. Having a site of 130KB compressed to 20KB is no exception. I've even read an artice somewhere that states that compressing the output actually saves server resources. The compression adds a litte bit of overhead, but because the download is much shorter worker threads are released faster and you'll need less of them for the same load. Apparantly the reduced memory usage more than compsensates for the compression overhead. Don't forget to enable the compression for *all* text-based formats: javascript, css, xml, they can all be served in compressed state. No amount of whitespace stripping will come close to what gzip can do. Don't work hard for your server, let it work for you. > > The cost of opening and closing <?php ?> blocks would certainly cease > to be an issue if a bytecode cache were standard equipment in PHP. > That's way overdue honestly. In PHP6 the APC cache will be native. However, installing it from pecl is about 2 minutes of work so again, a no-brainer to install. If you need really scary efficiency you can turn APC's stat feature off so it won't check if the file has been updated since it was cached. Of course you'll need to clear the apc cache when you upload updates, but for the rest of the time the site will run almost completely from memory. You could even extend the cache:clear to also dump the apc cache. For stuff that changes often you can simply put a .htaccess in that directory and turn stat back on for that dir only, but maybe increase the delay between updates from the default 2 seconds to 10 or 20. It would almost be as if your site runs from a ramdisk. It would become insanely fast and the drives may even live a little longer :) When using mysql for your database for example, and configuring it properly so it can do most of it's work from memory. Also, check the indexes on your tables. The folks a mysqlperformanceblog.com often write about how they benchmark their queries so you'll find all the information you need on there somewhere. It usually boils down to running your query with EXPLAIN prepended to it so mysql shows how it's handling the query, and which keys (if any) are used. Simply clicking the INDEX icon on the right column in phpmyadmin can increase a query's speed 10x or more. Of course, benchmarking all your queries can be a pain, so use symfony's dev toolbar, it shows how much time each part of your site needed to process. Usually, the whole thing is quite fast except for 2 or 3 parts. If those parts are slowed down because of a difficult query (or a simple one on a very large badly indexed table) and you can cut the query time in, say half, that would make your whole site twice as fast without even having to change any code. ... just a few things that are quite simple to do but offer a much much bigger increase in performance than most code-optimisations could. My motto is to never sacrifice readability and maintainability for raw speed. Hardware is much cheaper than time spent optimizing code. I made a new fileserver at home with an Intel Atom 330 mini-itx board a few weeks ago. I put 2GB ram in there: the ram was only 19 euros ! I can't even write a page of code for that money.. let alone rebuild a complete website. > > On Mon, Jan 26, 2009 at 9:30 AM, colnector (colnect.com) > <[email protected]> wrote: >> >> The questions also appear on: >> http://www.symfony-project.org/forum/index.php/m/70751/#msg_70751 >> and >> http://www.symfony-project.org/forum/index.php/t/18496/ >> >> Symfony templates are simple HTML embedded with PHP in them. >> For this reason they present the following downsides: >> * An extra amount of unneeded whitespace exists. Since you'd prefer to >> have a readable file, you organize it nicely. However, the generates >> files are needlessly bigger. >> * There's a price for PHP going in and out of scripting mode by using >> <?php and later ?>. >> * There's a price for calling PHP's echo again and again instead of >> once. >> >> Though these prices may be negligible for some sites, I feel they are >> becoming more and more costly for dynamic sites. Also, the template is >> not that readable with <?php and ?> cluttering it everywhere. >> >> Your opinions / insights are welcomed. >> >> Here's a sample of two alternative: >> >> Symfony style: >> >> <ul> >> <li><?php echo link_to('1', 'module/action');?></li> >> <li><?php echo link_to('2', 'module/action');?></li> >> <li><?php echo link_to('3', 'module/action');?></li> >> <li><?php echo link_to('4', 'module/action');?></li> >> <li><?php echo link_to('5', 'module/action');?></li> >> <li><?php echo link_to('6', 'module/action');?></li> >> </ul> >> >> >> >> A more optimized PHP script could be: >> >> <?php echo '<ul><li>' >> .link_to('1', 'module/action') >> .'</li><li>' >> .link_to('2', 'module/action') >> .'</li><li>' >> .link_to('3', 'module/action') >> .'</li><li>' >> .link_to('4', 'module/action') >> .'</li><li>' >> .link_to('5', 'module/action') >> .'</li><li>' >> .link_to('6', 'module/action') >> .'</li></ul>' >> ; >> >> >> >> The second script, although looks less like HTML, produces a >> whitespace-free output, uses a single echo command and doesn't force >> PHP's parser to go back and forth. Of course in this small example the >> differences are meaningless but I hope you understand my point. >> >> Your opinions / insights are welcomed. >> > >> > > > > -- > Tom Boutell > > www.punkave.com > www.boutell.com > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/symfony-devs?hl=en -~----------~----~----~----~------~----~------~--~---
