Welcome Guest, Not a member yet? Register   Sign In
Minimalising CodeIgniter Code
#1

[eluser]lachavvy[/eluser]
Hi there,

I have a website that's almost complete but now that I look at my code, I have a model that is of around 12kb in size due to many returns and spaces. Is it worth while - for performance issues - to remove all this white space to reduce the file size?

The website is running fairly quickly as it is, but I'm thinking in the future when it might have a lot more information, every second counts. Do you normally remove all this space in your code?

Many thanks.
#2

[eluser]Vheissu[/eluser]
PHP ignores the whitespace, so other than reducing the file size from 12kb which in my opinion is really tiny compared to some single scripts I've seen written in PHP, the only way to increase performance is to optimise your code. Find bottlenecks like expensive use of functions like call_user_func_array, etc.
#3

[eluser]lachavvy[/eluser]
Thanks Vhesissu for the quick reply.

I didn't know PHP ignores the white space, that's excellent cheers!
#4

[eluser]Vheissu[/eluser]
No worries dude. If you're after increasing performance though and you don't already use some form of caching, do a Google for "Php bytecode caching" - more specifically maybe "Php APC" which is Alternative PHP Caching which from my understanding compiles you're PHP scripts to machine code, which the PHP interpreter is able to load much faster than an uncompiled bytecode PHP script.

I'm not an expert on these things though, I know how they work, but you might want to Google around a bit. PHP scripts with APC enabled makes the language faster in some benchmarks I've seen than Python.
#5

[eluser]Unknown[/eluser]
Vheissu is correct, the overhead of that extra whitespace is basically negligible. As inefficient as it is that PHP compiles the script every time someone visits your site, that's probably not an issue either. APC isn't trivial to get working correctly and can cause issues, so unless you definitely need it I wouldn't bother.

As a general rule you shouldn't be thinking about optimisation, especially micro-optimisation, unless there is actually a speed issue! If your site does start running slowly in the future then you should profile it to find out why - the most likely causes are either inefficient scripts or datastore bottlenecks, PHP's execution speed only becomes the bottleneck once you've optimised the hell out of everything else.
#6

[eluser]John_Betong_002[/eluser]
Rather than assume PHP file size has a detrimental performance impact, have you tried the following?

// Profiler
http://ellislab.com/codeigniter/user-gui...iling.html

// one of many tools to monitor performance
http://siteloadtest.com
http://tools.pingdom.com
http://www.sitespeedlab.com

// Google Webmaster Tools - Fetch as Googlebot - Download Time185
https://www.google.com/webmasters/tools/googlebot-fetch
 
 
Once the initial bottleneck has been pinpointed then try:

// Caching
http://ellislab.com/codeigniter/user-gui...ching.html

// Caching Driver
http://ellislab.com/codeigniter/user-gui...ching.html

// Database Caching Class
http://ellislab.com/codeigniter/user-gui...ching.html
 
 
#7

[eluser]Vheissu[/eluser]
My rule of thumb for optimising all of my Codeigniter projects is the following simple list:

* If it can be cached, cache it. This includes all your view files and database queries.
* Don't autoload anything you're not constantly using. For example autoloading a database class is acceptable for a database heavy application, but not for a static website with one or two sporadic database queries.
* Use an ORM (not sure in terms of performance what this gives you over the standard CI query builder, just makes my life easier for advanced joins).
* Combine and minify all Javascript and CSS respectively.
* Combine all of your images into an image sprite map to reduce page requests.
* If you use jQuery, optimise your query selectors and make sure when querying by class, you're providing context.
* Don't use Javascript timers if you don't need too.
* Gzip.
* Compress and remove any excess meta info in your PNG images (especially if you use Fireworks to create or edit them).
#8

[eluser]waynhall[/eluser]
Nice List!

[quote author="Vheissu" date="1312263694"]
* Combine and minify all Javascript and CSS respectively.
* Compress and remove any excess meta info in your PNG images (especially if you use Fireworks to create or edit them).[/quote]

HTML5 Boilerplate comes with a build tool that helps you do these two. After using it with CodeIgniter a couple times, I decided to package HTML5 Boilerplate and CI together as one, for starting new web projects: Igniterplate




Theme © iAndrew 2016 - Forum software by © MyBB