Unconditionally, on all web requests (including api.php, rest.php, load.php, etc.) we create the DBLoadBalancerFactory service in order to inject some request-specific meta data:
MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->setRequestInfo( [ 'IPAddress' => $wgRequest->getIP(), … ] );
To construct the DBLoadBalancerFactory service, it spend 2% of the time doing:
- creates LBFactory
- creates WANObjectCache
- creates getStatsdDataFactory
- creates and initialises MemcachedPeclBagOStuff
And to compute WebRequest::getIP it spends another 1%:
Let's look at what these constructors are doing and defer what we can so that the instantiation is a cheap as it can be.