rdbms: Lazy-init DatabaseDomain::getId()
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 28 Sep 2016 21:01:04 +0000 (22:01 +0100)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 28 Sep 2016 21:50:17 +0000 (21:50 +0000)
Follows-up 847b91b.

Noticed that in Xenon profiles, about 25% of Database::__construct
time is spent in array_map, via DatabaseDomain::convertToString.

* Database::__construct
  * DatabaseDomain::__construct/convertToString/array_map
  * DatabaseDomain::newUnspecified
    * DatabaseDomain::__construct/convertToString/array_map
  * DatabaseMysqlBase::open
    * mysqli::*

Change-Id: Ib5ae7d1d03b27df504a7e5f552e36a0ca6fcf97e

includes/libs/rdbms/database/DatabaseDomain.php

index 01b6b21..a3ae6f1 100644 (file)
@@ -51,7 +51,6 @@ class DatabaseDomain {
                        throw new InvalidArgumentException( "Prefix must be a string." );
                }
                $this->prefix = $prefix;
-               $this->equivalentString = $this->convertToString();
        }
 
        /**
@@ -105,7 +104,7 @@ class DatabaseDomain {
                        );
                }
 
-               return ( $this->equivalentString === $other );
+               return ( $this->getId() === $other );
        }
 
        /**
@@ -133,6 +132,10 @@ class DatabaseDomain {
         * @return string
         */
        public function getId() {
+               if ( $this->equivalentString === null ) {
+                       $this->equivalentString = $this->convertToString();
+               }
+
                return $this->equivalentString;
        }