Page MenuHomePhabricator

ServiceContainer: Allow static methods to be used for wiring
Open, LowPublic

Description

Currently, ServiceContainer expects wiring to be defined as an array of instantiator functions. This could be done just as well as static methods in a class. This would potentially improve performance, since it avoids creating a long list of closures when loading the wiring.

Event Timeline

Change 531288 had a related patch set uploaded (by Daniel Kinzler; owner: Daniel Kinzler):
[mediawiki/core@master] WIP: use classes as wiring.

https://gerrit.wikimedia.org/r/531288

From a perf perspective, I've not perceived the status quo as needing better run-time performance. I don't recall seeing the middleware between MediaWikiServices and ServiceWiring.php take up much if any time in flame graphs or debug traces.

Typically the frame for MediaWikiServices::getSomething, through frames ServiceContainer::get, ServiceContainer::createService and {closure:ServiceWiring:#Something} are reported as taking the same amount of time, as if they go directly from one to the other. Eg. in case of getResourceLoader() from yesterday's flame graph I see a factor of ~0.002 difference (e.g. 678 vs 676 samples).

If changing this is preferred for other reasons, we have no objections so long as performance is the same or better. If it is motivated by performance, then I'd recommend measuring the creation time for a few services and determine the impact on latency with a representative production workload.

Krinkle triaged this task as Medium priority.Mar 31 2020, 5:26 PM
Krinkle edited projects, added Performance-Team (Radar); removed Performance-Team.
Krinkle moved this task from Limbo to Watching on the Performance-Team (Radar) board.

@Krinkle: IIRC the performance concern was the time taken by ServiceWiring.php itself, creating all the closures and putting them into an array. The time for that would be accounted under MediaWikiServices::newInstance()ServiceContainer::loadWiringFiles(), I believe, not under the getter for an individual service.

At https://gerrit.wikimedia.org/r/c/mediawiki/core/+/531288#message-f1da7e094986f91f0b3189f49e43b9aeb974f629 @tstarling measured a 200us improvement in wall clock time for a simple request to the REST API.

There's also mentioned that this change might improve the readability of the wiring file.

daniel lowered the priority of this task from Medium to Low.Dec 2 2020, 12:14 PM

Moving to roadmapping process. It's not much work, maybe a couple of weeks.