Magento 2 instantiating classes through object manager factory

The reason is performance. Instantiation through new is slightly faster than reflection. Most classes have less than 8 arguments so this switch covers most cases.

Maybe it'll be removed.


The performance gain is almost invisible. When I try to instantiate 1000000 objects with the 2 methods, here is the result :

enter image description here

I'm using Magento 2 Beta and PHP version (see below)

PHP 5.6.12-1+deb.sury.org~trusty+1 (cli) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans

In order to make this test, I used this script