From a11863a0af42a360ea5eab7669b742fbc72f1b35 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 31 Aug 2019 22:16:08 +0100 Subject: [PATCH] ProxyLookup: Optimise in_array in isConfiguredProxy() This is called on all page loads by WebRequest::getIP(), from Setup.php. Strict in_array can easily make it 4 times faster (reduce by 75%). For example, with an array containing 5 short strings and looking up a 6th similar string that is not in the list, repeated 100x: loose: 2.410 ms, 2.731 ms, 2.367 ms strict: 0.649 ms, 0.668 ms, 0.653 ms The larger the array to search through, the bigger the difference becomes as it speeds up each internal comparison. (PHP 7.2.20) Bug: T189966 Change-Id: I6742dfa0a6d44b15294695b15ffe4885cb6a5310 --- includes/ProxyLookup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/ProxyLookup.php b/includes/ProxyLookup.php index 246ae95ae9..7450bb91dc 100644 --- a/includes/ProxyLookup.php +++ b/includes/ProxyLookup.php @@ -58,7 +58,7 @@ class ProxyLookup { */ public function isConfiguredProxy( $ip ) { // Quick check of known singular proxy servers - if ( in_array( $ip, $this->proxyServers ) ) { + if ( in_array( $ip, $this->proxyServers, true ) ) { return true; } -- 2.20.1