10

I've made some changes for a php framework to suport namespaces and the result wasn't as expected. For a simple test (mostly framework classes loaded) the execution time slowed down with ~10%.

From your experience, is it worth it to use namespaces on large apps (considering the actual development level of PHP)?

user unknown
  • 35,537
  • 11
  • 75
  • 121
Tudor
  • 1,133
  • 1
  • 12
  • 28
  • I can hardly believe just introducing namespaces without any other significant changes would impact performance by that much. Could you perhaps try proifling the app with xdebug (preferably before and after your changes) to see where the time goes? One possible cause that comes to my mind could be a low performace class autoloader. – Mchl Feb 07 '12 at 14:45
  • No namespace is not bad for performance. But it really use full when you work on large applications. – PHP Connect Feb 07 '12 at 14:46
  • Maybe related to http://stackoverflow.com/q/2709375/39321 ? – Svish Feb 07 '12 at 14:51
  • @Mchl i'll do some tests for each individual process to see where's the big slow down ... i'll edit the question later with new results. – Tudor Feb 07 '12 at 14:56
  • @PHP Connect what do you mean by "it really use full" ? – Tudor Feb 07 '12 at 14:57
  • No, namespaces are good, they can even improve performace because using autoloading becomes much easier with namespaces and autoloading improves performance – Dmitri Snytkine Feb 07 '12 at 16:19
  • namespaces important to avoid conflict between your library and library. I have facing so many issues when same name of class found in other library also. Other way is too avoid is this to use class prefix but i prefer namespaces. – PHP Connect Feb 07 '12 at 16:29
  • possible duplicate of [php namespace benchmark](http://stackoverflow.com/questions/5331642/php-namespace-benchmark) – Lightness Races in Orbit Feb 08 '12 at 13:11
  • 1
    @TudorTudor: "it's really useful" probably. – Lightness Races in Orbit Feb 08 '12 at 13:11
  • I don't suppose you can release the before/after code that you benchmarked? Even better, if anyone has it, I'd love to see a minimalist example that shows the slowdown. – Darren Cook Nov 16 '12 at 02:15

1 Answers1

4

The accepted answer on php namespace benchmark is a good way of looking at this.

I would use namespaces in pretty much any OO application I write in PHP now, it saves a lot of headaches (especially in larger projects) with clashing names. You just need to be aware of the limitations of namespaces in PHP.

http://www.php.net/manual/en/language.namespaces.faq.php

Community
  • 1
  • 1
Garry Welding
  • 3,599
  • 1
  • 29
  • 46
  • I understand the concept of namespaces but the thing was that execution slow down that amased me ... Anyway ill stick with namespaces and test the framework later (don't have the patience for optimisation right now) . Ty all for your answeres ! – Tudor Feb 08 '12 at 23:26