get_instance vs $GLOBALS |
[eluser]korpirkor[/eluser]
Hi, I have question about performance with using &get;_instance() CodeIgniter is promoting using get_instance() all the time - in libraries, helpers etc I was always thinking that accessing to a variable is faster than calling a function. So, wouldn't it be faster call just once in Loader Class: $GLOBALS['CI'] =& get_instance(); And after that just use $GLOBALS['CI'] ? This way we don't even need to think: use $this or get_instance(). What do You think ? Regards, Cezary Nowak
[eluser]Pascal Kriete[/eluser]
In theory $CI is already a global variable: Code: global $CI; However, we do tweak the bootstrap code occasionally, so relying on certain global variables being present is probably a bad idea. In either case you're really optimizing the long tail. Refactoring to remove a file include or database call will more than make up for the performance lost from using get_instance().
[eluser]John_Betong_002[/eluser]
http://dhorrigan.com/blog/article/codeig...eferences/
[eluser]korpirkor[/eluser]
[quote author="Pascal Kriete" date="1306312327"]In either case you're really optimizing the long tail. Refactoring to remove a file include or database call will more than make up for the performance lost from using get_instance().[/quote]I'm aware of that But now there are few frameworks faster than CI - yiiframework or DOOPHP... I think we shold think how to get lead :-) |
Welcome Guest, Not a member yet? Register Sign In |