Optimizing some selectors in /modules/controller.js in DiscussionTools repository.
Replace:
$( '#ca-addsection a' )
with:
$( '#ca-addsection' ).find( 'a' )
Because as CSS selectors are evaluated right-to-left, that was analyzing each and every <a> of the page.
Also, replace:
$( '#t-permalink a, #coll-download-as-rl a' )
with:
$( '#t-permalink' ).add( '#coll-download-as-rl' ).find( 'a' )
Because this way jQuery uses two getElementById's, which are extremely fast.
Benchmark for 10,000 iterations (less is better):
$( '#t-permalink a, #coll-download-as-rl a' ) $( '#t-permalink, #coll-download-as-rl' ).find( 'a' ) $( '#t-permalink' ).add( '#coll-download-as-rl' ).find( 'a' ) 3428 ms (which means it takes a third of a ms, just to execute this selector) 1042 ms 146 ms
Two similar optimizations should be applied to /modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js in VisualEditor repository.