RobotLegs VS PureMVC: performance battle!
We all know that using framework in you application will hurt performance, and Flash has long and sad history of performance problems. I decided to find out how much exactly performance using framework costs us. As in last post I focus on 2 most popular frameworks: RobotLegs and PureMVC.
Run PureMVC tests [Source code: PureMVCSpeedTest.zip]
| RobotLegs | PureMVC | RL runs/1ms | PMVC runs/1ms | |
| Core init: | 5.00000 | 2.00000 | ||
| Time to run 1 command: | ||||
| Command with nothing: | 0.00690 | 0.00195 | 144.9 | 513.3 |
| Command with parameter: | 0.00996 | 0.00196 | 100.4 | 511.0 |
| >>> added by getting parameters: | 0.00306 | 0.00001 | ||
| Command with Model: | 0.01062 | 0.00208 | 94.2 | 480.3 |
| >>> added by getting model: | 0.00372 | 0.00013 | ||
| Command with Model and View call: | 0.01299 | 0.00387 | 77.0 | 258.3 |
| >>> added by 1 communication to mediator: | 0.00237 | 0.00179 | ||
| Time to register 1 mediator: | ||||
| >> max 1000 mediators: | 0.04700 | 0.02000 | 21.3 | 50.0 |
| >>> max 2000 mediators: | 0.04650 | 0.02050 | 21.5 | 48.8 |
| >>> max 5000 mediators: | 0.04400 | 0.02040 | 22.7 | 49.0 |
| Time to remove 1 mediator: | ||||
| >>> max 1000 mediators: | 0.01100 | 0.05600 | 90.9 | 17.9 |
| >>> max 2000 mediators: | 0.02000 | 0.09850 | 50.0 | 10.2 |
| >>> max 5000 mediators: | 0.03600 | 0.22980 | 27.8 | 4.4 |
| Communication with many mediators: | ||||
| Message to 1 receiving mediators: | 0.00101 | 0.00053 | 994.0 | 1902.9 |
| Message to 100 receiving mediators: | 0.02972 | 0.06111 | 33.6 | 16.4 |
| >>> time for 1 communication: | 0.00030 | 0.00061 | ||
| Message to 200 receiving mediators: | 0.05944 | 0.12096 | 16.8 | 8.3 |
| >>> time for 1 communication: | 0.00030 | 0.00060 | ||
| Message to 500 receiving mediators: | 0.14930 | 0.29828 | 6.7 | 3.4 |
| >>> time for 1 communication: | 0.00030 | 0.00060 | ||
| Message to 1000 receiving mediators: | 0.29290 | 0.59093 | 3.4 | 1.7 |
| >>> time for 1 communication: | 0.00029 | 0.00059 |
PC I tested on:
- Windows 7 Professional 64-bit
- Intel(R) Core(TM)2 Quad CPU Q9400 @ 2.66GHz (4 CPUs), ~2.7GHz
- 4096MB RAM
- Flash Player WIN 11,1,102,55 (Release)
Data analysis:
Command Execution:
RobotLegs commands are slow. The main reason why it’s so slow is the nature of how dependency injection works. Empty Robotlegs command will cost you 0.007ms, and every injection you make will cost you extra 0.003ms.
If you extend Comamnd class that is provided with RobotLegs you will get 5 injection in it , and most of it is not used. So it’s almost always better just create your own command classes and inject only objects you need in it.
For example if we take 3 injections as average per command you will be able to create 62 such commands to waste 1ms. Compared to PureMVC that allows 440 such commands for 1ms it’s a huge difference, and that something that I am not happy about.
In the perfect world it would not be a problem. If you use framework careful – you will not have any(or only couple) commands looping, and the commands you will have will be one shot rare very important events. But we are not living in the perfect world – in big teams people write all kind of code.. and sometimes you just don’t have time to make it right.. sometimes you are forced to ‘hack in’ quick solutions, and having performance sucker in core layer of your application does not sound nice.
I was assured in RobotLegs forum that RobotLegs version 2 will improve the speed, and I will measure it as soon as I will able to.
Also it’s should be possible to pool commands to solve this issue(as Till Schneidereit suggested), but this can be dangerous if you forget that your commands can’t hold state…
Getting stuff:
Getting proxies in PureMVC is very fast action. It involves couple of function calls and returns indexed data. You can do 3500 of those actions to lose 1ms.
In RobotLegs getting models (or getting parameters… or anything else for that matter) is more costly because you get it injected. You can do 450 of those actions to lose 1ms.
It’s sad that RobotLegs has this big overhead, and you have to be careful how much stuff you inject. (especially in commands…)
Creating/removing mediators:
In most cases you will want to set up most of your views and mediators before application is extensiveness used, and keep only exceptional rare events to force mediator creation.. (like showing new window on user click..) so this number is not so important.
Still it’s good to know that you can pair 25 views with mediators in RobotLegs, and 50 in PureMVC to waste 1ms.
Removal of mediators is very fast in RobotLegs(100 actions for 1ms), and very slow in PureMVC. Actually PureMVC removes objects much slower then adds them. (2-5 times slower). But still… because you don’t usually spam your application with views creation/removal (not in framework level at least) I don’t see any of those numbers becoming a problem.
Communication:
Both RobotLegs and PureMVC have good communication.
In PureMVC creation of 1 message costs less time. So you can create 1000 messages that has 1 listener, in RobotLegs you can create 500 messages that has 1 listener and use 1ms.
But! If you have to reach more listeners RobotLegs becomes faster! My quick test showed that if you have 7 objects listening for message both RobotLegs and PureMVC takes same amount of time. And if you have even more listeners – RobotLegs starts perform better.
Still… both frameworks will do good job letting objects to communicate.
Conclusion:
PureMVC shows better performance out of those 2 frameworks, and you have to outweigh it with RobotLegs benefits(dependency injection, cleaner code..) if you are making the choice beat-wean those two.
Still… If you do small to medium projects, both frameworks should do fine for you, and in long run you should only win.
If you plan on doing huge project – you have to be careful to use any framework, and if you do – use it *correctly*, or you will run into performance problems.
I hope this post will help you estimate framework performance costs and let you plan your projects better.
Have fun!
2012.01.10 EDIT:
- Thanks to Shaun Smith I learned my mistake of extending Command class for RobotLegs commands. In most cases its better to write your own command classes. After the change Robotlegs commands looks better, but they are still very slow.
- Code cleaned up and split into 2 projects.
- PureMVC iteration count increased for better precision.
Excellent! Thanks for taking the time to do this, and for sharing the results. I took a quick look through the code and made some minor tweaks to even things out a bit. The source is over on GitHub:
https://github.com/darscan/framework-speed-test
You can check out the diff here:
https://github.com/darscan/framework-speed-test/commit/af64690d686b22ae408027c5fd5757badd4322ef
As the commands weren’t actually using anything from the base MVCS command, and since PureMVC doesn’t supply any default dependencies, I made them plain commands. Injection is still performed on them though, so they’re probably still quite a bit slower than PureMVC’s.
The other thing was that the “delay” on the PerformanceTest was set to 1 leaving no cool down between tests and putting to much strain on the player. I set this to 60 (the default is 50).
And then a minor one: I added a two second delay before starting up the context to allow the player to warm up.
Also, I only looked at the command side of things.. might take a peek at the mediator stuff at some other point. Anyway, that was fun, thanks again for posting.
I’d be really interested to see what the new results look like on your machine.
consider this solution http://flaemo.com/blog/?p=450