ProxyLookup: Optimise in_array in isConfiguredProxy()
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 31 Aug 2019 21:16:08 +0000 (22:16 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Sat, 31 Aug 2019 21:30:08 +0000 (22:30 +0100)
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

index 246ae95..7450bb9 100644 (file)
@@ -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;
                }