In investigating T201801: Improve TitleValue, TitleFactory, TitleParser performance to be on-par with Title, one of the performance problems identified was the use of the Assert library. For example in TitleValue:
Assert::parameterType( 'integer', $namespace, '$namespace' ); Assert::parameterType( 'string', $dbkey, '$dbkey' ); Assert::parameterType( 'string', $fragment, '$fragment' ); Assert::parameterType( 'string', $interwiki, '$interwiki' ); // Sanity check, no full validation or normalization applied here! Assert::parameter( !preg_match( '/^_|[ \r\n\t]|_$/', $dbkey ), '$dbkey', "invalid DB key '$dbkey'" ); Assert::parameter( $dbkey !== '', '$dbkey', 'should not be empty' );
All of the type checks would be significantly faster if they were inlined instead.
[22:41:21] <TimStarling> it's obviously faster to use is_int() than Assert::parameterType(), look at the implementation of the latter
Usage in MediaWiki core: https://codesearch.wmflabs.org/core/?q=Assert%3A%3A&i=nope&files=&repos=
Requesting a performance review, mostly for how the library is used, and whether we should change the way we're using it.