Nikerabbit has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/346244 )

Change subject: Optimize expandWildcards
......................................................................

Optimize expandWildcards

StringMatcher::match was identified as a very hot function for
Special:LanguageStats. It is called by MessageGroups::expandWildards
a lot.

Optimized it for the common case of no wildcards. In translatewiki.net
I see following speed-ups:
[ 'core', 'freecol', 'out-freecol', '*' ] -> ~10% faster
[ 'core', 'freecol', 'out-freecol' ] -> ~99% faster

The reason is that we know only call StrinMatcher::match for items
containing wildcards. Previously for exact matches we were running
in_array( patterns, id ) for each message group id that exists, for
each aggregate message group. Meta has ~6300 groups, with many
aggregate groups with many subpages.

Bug: T160565
Change-Id: Ifdb515c194de0f75867e6c716035497015a7a8b1
---
M MessageGroups.php
1 file changed, 14 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate 
refs/changes/44/346244/1

diff --git a/MessageGroups.php b/MessageGroups.php
index 249e8ab..9ca4fc9 100644
--- a/MessageGroups.php
+++ b/MessageGroups.php
@@ -568,10 +568,22 @@
 
                $ids = (array)$ids;
                foreach ( $ids as $index => $id ) {
-                       $ids[$index] = self::normalizeId( $id );
+                       // Fast path, no wildcards
+                       if ( strcspn( $id, '*?' ) === strlen( $id ) ) {
+                               $g = self::getGroup( $id );
+                               if ( $g ) {
+                                       $all[] = $g->getId();
+                               }
+                               unset( $ids[$index] );
+                       }
                }
 
-               $matcher = new StringMatcher( '', (array)$ids );
+               if ( $ids === [] ) {
+                       return $all;
+               }
+
+               // Slow path for the ones with wildcards
+               $matcher = new StringMatcher( '', $ids );
                foreach ( self::getAllGroups() as $id => $_ ) {
                        if ( $matcher->match( $id ) ) {
                                $all[] = $id;

-- 
To view, visit https://gerrit.wikimedia.org/r/346244
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifdb515c194de0f75867e6c716035497015a7a8b1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to