Page MenuHomePhabricator

Linker::link is inefficient
Closed, DeclinedPublic

Description

In https://gerrit.wikimedia.org/r/#/c/29879/ I was able to save tens of megabytes of memory by using Html::element( 'a' ) instead of Linker::link.

Profiling also confirms my observations: over 20k per call and 0.5 ms per call. Not much per se, but it really adds up when making hundreds or even thousands of links like I do.

Part of this might come from hooks: Translate and SemanticForms are using hooks in linker.


Version: 1.21.x
Severity: normal
URL: http://translatewiki.net/w/profileinfo.php?filter=Linker%3A%3A&sort=time&expand=%2CLinker%3A%3Alink

Details

Reference
bz41377

Related Objects

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 1:14 AM
bzimport set Reference to bz41377.
bzimport added a subscriber: Unknown Object (MLST).

We should probably put real profiling around those hook calls. Or do we do that implicitly?

All hook calls are profiled, you just need to know the name of the hooked-up functions to search for them.

Sounds unreliable. We should also profile whole combined calls for separation from the surrounding function.

We've got another bit of profiling there for the known stuff that does db calls. How long does that take?

Can we close this since @Legoktm deprecated this static function.

I have not done any intense profiling of LinkRenderer, so it's possible this performance problem still exists. It doesn't appear that https://translatewiki.net/w/profileinfo.php works anymore though?

I only enable profiling when I'm profiling something, and that hasn't happened again since the whole profiling thing changed :). Besides, the hottest paths using Linker::link were already replaced earlier to construct links manually. Also HHVM might have changed the situation considerably.

Legoktm changed the task status from Open to Stalled.Sep 16 2016, 2:37 AM

Okay, I'll mark it for stalled now. Though now that I've read the above patch, I'm not very surprised that if you call Linker:link() 5000 times it's rather slow. Each call (back then) probably had 10-15 function calls, so times 5000 that would be 50000 function calls, and if you can skip all of those, it would be substantially faster.

Krinkle subscribed.

Declining for know as I'm not aware of current user-facing performance issues involving this method. In general, the majority of the code base is not critical for performance and if one were to take any of those parts of an extreme, a bottleneck will likely emerge. If and when that happens, we have to trade finding a way to optimise the method general, develop alternate means for that use case (e.g. batching), or to decide it isn't for that purpose and re-approach the original use case.

In this case, given in the last 7 years, this one page for the Translate extension appears to have been the only case where this was an issue, a local workaround was used. Which seems adequate. If this workaround becomes problematic or if the need arises elsewhere, feel free to re-open and reach out to Core Platform and/or Performance for help.