Help US :  

CC Classes And Objects (Curtailed Concise Classes And Trimmed Or Reduced Objects)

@) Introduction:

Its a simple & effective but still very much new and yet un-touched thing in software engineering and memory management. There are lots of applications out there but no-one actually has implemented it or even thought about it. This feature must be a part compiler or interpreter but as its not till date in any of them, we need separate application to do such work for us. There are many experts who talk about memory management and different methods to do memory management but they also ...

So, here it comes to all of you for the very first time, a theory originally devised and also practically developed by obviously, 'developer' and 'owner' of this site ! Ok enough of self praising.

As the name suggests, its all about reducing a class to the required functions and using object of that reduced class to improve memory consumption of an application.

If it seems abstruse, then don't look at the name. In simple words, this theory is all about loading only those function of a class that are actually required and are going to be used during execution of the application for specific scenario (i.e.: functionality, page or view).

In object oriented practice, if a function of some class is required then that class file is loaded and after creating its object that function is used. Some nice developers also destroy that object after it is no more required.

But what about all other extra functions of that class which were never used during that time. All of them were also loaded un-necessarily and occupied extra bit of memory. So, we have a plan for all those functions !

Yes, and the plan is not to load them in memory at all, as they are not going to be used along with the function/s of our interest.

@) Benefits:

1) Reduces amount of time and memory memory required for and application to load and run [direct effect]

2) Increases amount of requests an application can handle for a given set of resources [indirect effect of first one]

3) Increases amount of applications that can be run together [indirect effect of first one]

4) Reduces amount of memory and cpu used of a server machine [indirect effect of first one]

5) Improves performances of a host server and reduces its chances of getting short of memory (and cpu indirectly) [indirect effect of first one]

Thus saving on memory (also results in indirect saving of cpu) consumption of an application, benefits in many ways.

Hey, do any one still doubt the theory and believe that it is useless ? Yes, we know there may be some people who are not open to new things and they will argue there is really no need to use any such thing in practical situations.

So, lets have a detailed look in to this Next-Gen theory of memory management and performance improvement; which is now also practically tested and proven.

@) More About Theory (In Detail):

Let us consider example of web applications (but this is equally important for desktop and mobile applications also).

Once upon a time there was an era, when most of the websites were nothing but a bunch of simple informative static pages. And in this age websites have transformed to web applications which are used for almost everything and many of them even require many complex logic, high security check and lot of processing, etc. i don't need to say much on this right ?

Although this theory was first developed with web development in mind, it is equally useful for any desktop / mobile / web or any other application.

It is also useful for applications built using non-oop (procedural) programming. But, as said before we will consider here oop example for better understanding of the concept and also because nowadays oop is defacto paradigm for application development.

There are many classes used and loaded in memory during one single webpage request, even in medium or some times no complex web applications and specially when using some framework.

As everyone knows web applications are stored on server and that server req. high uptime to server those applications to every request with its best performance. Moreover, most of the servers server more than one websites at same time. This makes memory and cpu resources of the server very precious as performance and working of not only one but many web applications are depend on the performance of their server.

There is an old saying that,"A lake is built-up of small water droplets". Similarly, small performance improvement on each application can result into a big performance gain for overall server and thus to those individual applications. Also, an application working on less memory means it can run swiftly on lesser resources.

Lets us consider an example of a shared server hosting 100 websites (many providers handle much more than this, but lets consider only 100).

By searching on internet you can find few articles where they have stated that Fat-Free Framework which is considered to be a very basic PHP framework with much minimal structure overload takes 1MB-3MB while drupal / wordpress took more than 20MB per single page req. and obviously web applications developed on it will take more time than it.

5MB for a web page req. is very much fine as per those figures and so we will consider every website to be using 5MB per page request. This makes memory consumption on shared web hosting with 100 sites and avg of 5MB memory per page req. with always 5 users of traffic for each web application to reach 2500 MB (= 2.5 GB), with increasing usage of web applications and online traffic these figures are always going to rise in future.

The amount of reduction in memory per class depends on value of ("functions req. per request" * "size of function code" / "total functions in that class").

Now, practically a web application with medium complexity or size developed on any framework or core php coding will definitely contain many big functions (big refers to no of characters in coding) in a class based upon functionalities required as per the entity denoted by that class and all those functions are obviously not required on every request.

On an average there are min. of 1-3 and max. of 5-7 functions required out of 10 functions.

This makes it on avg. 40-50 % of reduction, but the main parameter is size of function and not no of function.

Now, i need to remind you that we are not considering performance of any framework but applications built on them and even on core php coding.

Size of the functions written during development are mostly always higher (more than 90% of total functions are medium or big in size), i don't need to give numbers right ? So reducing no of function loaded in memory is definitely going to reduce size of application in memory.

Summarizing figures (note: figures considered here are very much practically possible but can be even more / less in many cases depending on type of server, size, traffic & type of web applications):

In our example we have 100 sites with 5 MB per page and 5 active requests for each 100 sites at to server at any given time making memory of 2.5 GB RAM usage at given time.

When consider usage of this api as per our coding estimate done above we can improve memory usage of around 40 - 50 % practically (not just in theory) for each request, which makes almost 2MB reduction for 5MB and 1GB in reduction out of 2.5GB (even if we consider lower lever value i.e. 40% reduction), resulting into actually only 1.5 GB of RAM to be used instead of 2.5GB for our scenario.

For desktop and mobile applications, memory management is even more important as in todays world of multi-processing many applications run at same time (and share resources of system) not only in desktop computers but also on mobile devices and even little savings on memory for each applications can result in a big overall performance of computers or mobile devices.

Are you thinking that all this is only hypothetical ? Just think about the classes and coding done in it for a fully developed web application and imagine the amount of functions and code there in. Do all of those functions and code really need to be loaded into memory every time for each and every functional request that is server by that class ?

No, all those are not required together at same time and for every request or page run. Thats why this theory being so simple theoretically it actually rocks practically.

http://www.plsein.tk//images/products/cc/cc_classes.png

So, after understanding the theory lets have a look at the actually implementation of that theory and performance improvement proof by a benchmark comparison.

@) Proof Of Concept (Benchmarks):

Benchmark done using XH-Prof and Graphviz on LAMP with php v5.3:

Followed are the results of benchmark that were carried out with only one class in total i.e. facebook.php used for getting login url and logout url of facebook.

The "_facebook.php" file is the one generated using our api which has implemented this theory and the normal "facebook.php" is original.

i) Below graph is generated using xhprof + graphviz. You can clearly see 1 millisecond of time reduced for "_facebook.php" which is generated cc-class file (which contains only getLoginUrl, getLogoutUrl and other related functions + class properties or class variables) of the original facebook.php file.

http://www.plsein.tk//images/products/cc/XHProf_CallGraph_CC_(Cutrailed_Concise)_Classes.png

ii) Below image shows stats regarding time & memory improvement. While looking at below stats please look at them carefully, the time taken is 1 ms less and memory 41.5% less, when using "_facebook.php" (which is the new generated class file) is much lesser compared to the original "facebook.php".

http://www.plsein.tk//images/products/cc/XHProf_Hierarchical_Profiler_Report_For_CC_(Cutrailed_Concise)_Classes.png

I think those were enough as evidence. Hope you understood, but if not then feel free to Contact us regarding any doubts. If someone still don't believe it, they can try using this api and do benchmark on there own.

Note: The 40% reduction in memory is an average calculated estimate, done by our expert developers based on their immense technical knowledge & experience. And result of our benchmark for selected scenario also came around that estimate but not exactly 40% and for any one else who uses this, the amount of reduction may be more or less based upon value of ("functions req. per request" * "size of function code" / "total functions in that class") depending on their scenario.

If you are doing benchmark make sure you check with multiple calls and turn opcode caching off. For those who did benchmark on their own and some how got (or managed to get) wrong results or still don't believe this theory, then what can we say; its their bad luck.

@) About the product:

CC Classes & Objects [Curtailed Concise Classes And Trimmed (OR Reduced) Objects] API, currently provides facility to generate curtailed - concise classes from a php class. So, implement it to use trimmed or reduced objects in your project and reduce the heaviness of the application.

@) More on usage:

For more details on usage visit products page.