Preloading vs lazy loading
A few days ago I found a blog post about benchmarks of symfony 2 vs other frameworks (couldn’t find the link to it again) It was mentioned that symfony2 is 20% faster than solar on a hello world test. This got my attention as symfony2 looks pretty heavy based on its features.
I tried searching for the post again and found a post from Paul M Jones The post mentions that symfony2 uses preloading and when solar is made with preloading and the same tests are repeated, solar turned out to be 28% faster than symfony2.
Though the benchmarking process might be different and the real effect on a real project might be different. A change from -20% to 28% change in speed is sure to draw some attention.
Later on I tried it with mAdserve and with just microtime(true) at the start and end to get the time elapsed in layman-ish ways, showed about 10 ms bonus over non-preloaded version. Though another simple test with apache benchmark with 100,000 requests with 20 concurrent users to my laptop gave some 20 requests per second advantage to the setup without preloading…
How does it work?
First, a refresh on lazy loading. When you have many classes in a project, it can be pretty messy to attach all dependencies on top of every file and loading it all can cause considerable blow to memory and speed. To overcome this, we use the autoloader (spl_autoload_register or less flexible __autoload). Implementations can be seen in DokuWiki and ThinkUp.
If you try to dump a list of files loaded with the autoloader, you will find that some classes get loaded with every (almost) request. For example the Request, Session, Front Controller, Resolver, Default Command, Dependency Injection Factory etc… Any logic being implemented to autoload these is essentially a waste of time as they get loaded on every load anyway. So, instead of making our autoloader load these, we can stuff the require statements for them in one file. That sure does increase performance, but PHP still has to concatenate a string (considering you save full path to the app in a constant and use relative paths from there), look for the file and pull all its contents in for every require_once statement. We could stuff all those classes into one file to save time. But we have been trained not to keep redundant code and open the box of worms. This is where code compiling comes in. We code it in one place, the original files and make a code compiler copy the classes to the separate file. Similar to Cache, we can write code to purge it periodically for recompiling (Though I cant find the usefulness of doing that), launch a purge with some event trigger (An update for example) or disable the feature completely and still have everything as is. Too much work for a little edge you say? Read the first para of this post again! Best of both worlds isn’t it?
mAdserve: Events and listeners or hooks
I was searching for “inspiration” for mAdserve’s architecture saw the video on how Drupal works. And I liked a lot of ideas behind it. For example, I absolutely love the hooks system. In mAdserve its more like MVC with a front controller so basically the hooks will be the names of your controllers.
For example you want to add a listener for the routing event and its identifier is “MadRouting” (All mAdserve events will have ‘Mad’ as the poor man’s namespacing) and your plugin name is “Test” so you name your controller “TestRouting” extend the “MadListener” class and mAdserve will automatically call TestRouting::listen() function.
That takes care of being called in but what about the data you need to manipulate. What Drupal does is that they add huge arrays for everything. But we are OOP and can use strictly defined classes so that you know and can trust the data you are getting. The base class I created within mAdserve is “MadEventData”. You can add read-write and read-only properties to it right now. But the best part with this is, with this structure you can make your own hooks in the modules and have others use them to build on top of you.
But that will eventually bring us to dependency-deadlocks and version compatibility issues. For which I am leaning towards Semantic Versioning and defining stricter API rules.
One of many ideas I have is that you can create interfaces for people to implement. For example I am creating Caching class now and I can add an interface on how you can extend it with a different caching driver. The parent class will basically look for a few functions in the individual implementation. Like with the initial release I plan to support crude filesystem caching only. Maybe overtime we can include memcache or APC?
Same goes for sessions and DBAL. Does that work for you at module levels too?
Open source from scratch
A new open source project is always a very interesting. You get to choose everything. Every little detail you hated in the softwares you have used till date, you get to fix them in yours!
I have recently started writing mAdserve from scratch and it is quite an experience to say the least. The knowledge I gained writing sambhuti is all coming to good use now. Its MVC, I have implemented the Front Controller and DAO as they have become my favorites over the past few months.
A new project is the right time for a new developer to learn as the code base hasn’t yet grown out of comprehensible proportions and is relatively easy to follow. The seasoned ones can jump in early to help out and save me from making the same mistake as everyone else. I hope with time I can move to be the maintainer of this project and it can run on its own.
PS: I am reading Producing Open Source Software on the side to gain more insight.
Game On!
Ashish Sharma (Pocha) shared about Google DevFest on facebook. Being a wannabe developer, I get excited about the talks and fests. The idea of meeting more developers, knowing about awesome new things to try out etc. So I started looking at all the events and found a very interesting one on Cross Platform Game Programming with Play’N. Which eventually landed me on the video for ForPlay(previous name for Play’N). I’ve recently discovered that I like framework-ish kinda code a lot better than the end result/product and this Play’N project is a good example. I like games and would love to start on game programming! Now the hurdle here is that I have absolutely no experience in Java and obviously none on GWT. So, I have downloaded GWT, apache ant, the JDK and lets see where this goes… This is my new 30-day challenge!
PS: Be prepared to see and get requests to test some popular stupid turn based game(s). If this goes well, I might have a facebook game in a month or two for you
Installing new plugins and templates
Earlier to download and install a plugin or a template in DokuWiki, we needed the download URL.
The fastest/simplest method for this needed you to :-
- Log into your admin panel and go to admin > plugin manager
- Open the DokuWiki Plugins list in another tab
- Type in the name/ of the plugin or author or any associated tag and hit search
- Copy link location on the “download” link
- Paste the URL in the text box and click “Download”
- Additional step to disable if you did not want it activated by default
Pretty long process huh? If you want more information about the plugin/template, you will have to open the details of the plugin in another new tab.
We’ve tried to make this simpler by providing an install tab into the new extension manager.
Now the steps are :-
- Log into your admin panel and go to admin > extension manager
- Type in the name of the plugin/template or author or any associated tag and hit search
- Click “Download” or “Download as disabled” if you want it disabled
And that’s it! No new tabs. No more copy pasting links. To get more info on the plugin/template just click “info” on it. the state of your search is saved as is and you can see all relevant information right on your install.
PS: At the time of writing the extension manager is still under active development and even though it is quite stable, we do not have a production ready release yet. But this should not break anything so you can go ahead and give it a spin
Staying creative
Vivek Rp Shared this one. After watching this I realized, I always setup lists, steps and guides for everything! lol
Love the graphics on this one. Do not agree with drinking coffee to stay creative though…
30 day challenge, the story begins
+Bill Gross shared this TED video. It made me think of the things I have missed out and never really done and should try.
Recent ideas:-
- A browser based text-editor
- A site similar to FOSS Factory more oriented towards developers and features.
- Education based game
- Thug Award (blog for stories of people thugged)
Those need a lot of time, it should be a simple one so that I can stick to it and keep doing it for the whole 30 days. But then not too mundane to feel bored and drop it midway…
Let the hacking begin
For quite some time I have this feeling that I do not have a clear log of everything I learn about being a programmer and also I do not mark and keep things I like (thumbs down if you thought of facebook just now)
Like on my Blog. I write about things in general, about things I learn from life and my thoughts. Most of my friends who read it are non-tech so I have to tone everything down keeping them in mind. Another aspect of this is somewhat more explain-able now after the G+ launch. As you have various circles in real life, you have various channels too (something I think social networks should take into account). I do not want my regular friends to get bombarded by stuff related to DokuWiki stuff for GSoC (Its my damn blog people, I can brag all I want here). All they’ll see is GSoC and all they’ll do is say “congrats” till the point when they start to think I am an own-fart-smelling snob (I do not necessarily disagree to it too). So I’ll sharing things I like related to tech, post updates for my projects, share TED talks, rant and talk about things I learn on the path becoming a true hacker.
At some point, I hope, hackers will help me learn and some day accept me into being one of them.
