commit 4ee8443a262e18c08b942aef313710b2c070a7a4
Author: Viktor Paladiichuk <vpaladiychuk@magento.com>
Date:   Thu Nov 16 18:55:15 2017 +0200

    SET-36: Memory limit exhausted during import of customers and addresses

diff -Nuar a/vendor/magento/module-customer-import-export/Model/Import/Address.php b/vendor/magento/module-customer-import-export/Model/Import/Address.php
--- a/vendor/magento/module-customer-import-export/Model/Import/Address.php
+++ b/vendor/magento/module-customer-import-export/Model/Import/Address.php
@@ -238,6 +238,11 @@ class Address extends AbstractCustomer
     protected $postcodeValidator;

     /**
+     * @var array
+     */
+    private $loadedAddresses;
+
+    /**
      * @param \Magento\Framework\Stdlib\StringUtils $string
      * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
      * @param \Magento\ImportExport\Model\ImportFactory $importFactory
@@ -368,21 +373,50 @@ class Address extends AbstractCustomer
      */
     protected function _initAddresses()
     {
-        /** @var $address \Magento\Customer\Model\Address */
-        foreach ($this->_addressCollection as $address) {
-            $customerId = $address->getParentId();
-            if (!isset($this->_addresses[$customerId])) {
-                $this->_addresses[$customerId] = [];
+        if ($this->_addressCollection->isLoaded()) {
+            /** @var $address \Magento\Customer\Model\Address */
+            foreach ($this->_addressCollection as $address) {
+                $customerId = $address->getParentId();
+                if (!isset($this->_addresses[$customerId])) {
+                    $this->_addresses[$customerId] = [];
+                }
+                $addressId = $address->getId();
+                if (!in_array($addressId, $this->_addresses[$customerId])) {
+                    $this->_addresses[$customerId][] = $addressId;
+                }
             }
-            $addressId = $address->getId();
-            if (!in_array($addressId, $this->_addresses[$customerId])) {
-                $this->_addresses[$customerId][] = $addressId;
+        } else {
+            foreach ($this->getLoadedAddresses() as $addressId => $address) {
+                $customerId = $address['parent_id'];
+                if (!isset($this->_addresses[$customerId])) {
+                    $this->_addresses[$customerId] = [];
+                }
+                if (!in_array($addressId, $this->_addresses[$customerId])) {
+                    $this->_addresses[$customerId][] = $addressId;
+                }
             }
         }
         return $this;
     }

     /**
+     * @return array
+     */
+    private function getLoadedAddresses()
+    {
+        if (empty($this->loadedAddresses)) {
+            $collection = clone $this->_addressCollection;
+            $table = $collection->getMainTable();
+            $select = $collection->getSelect();
+            $select->reset('columns');
+            $select->reset('from');
+            $select->from($table, ['entity_id', 'parent_id']);
+            $this->loadedAddresses = $collection->getResource()->getConnection()->fetchAssoc($select);
+        }
+        return $this->loadedAddresses;
+    }
+
+    /**
      * Initialize country regions hash for clever recognition
      *
      * @return $this
diff -Nuar a/vendor/magento/module-customer-import-export/Model/ResourceModel/Import/Customer/Storage.php b/vendor/magento/module-customer-import-export/Model/ResourceModel/Import/Customer/Storage.php
--- a/vendor/magento/module-customer-import-export/Model/ResourceModel/Import/Customer/Storage.php
+++ b/vendor/magento/module-customer-import-export/Model/ResourceModel/Import/Customer/Storage.php
@@ -117,13 +117,18 @@ class Storage
      */
     public function getCustomerId($email, $websiteId)
     {
-        // lazy loading
-        $this->load();
+        if (!isset($this->_customerIds[$email][$websiteId])) {
+            $collection = clone $this->_customerCollection;
+            $mainTable = $collection->getResource()->getEntityTable();

-        if (isset($this->_customerIds[$email][$websiteId])) {
-            return $this->_customerIds[$email][$websiteId];
-        }
+            $select = $collection->getSelect();
+            $select->reset();
+            $select->from($mainTable, ['entity_id']);
+            $select->where($mainTable . '.email = ?', $email);
+            $select->where($mainTable . '.website_id = ?', $websiteId);

-        return false;
+            $this->_customerIds[$email][$websiteId] = $collection->getResource()->getConnection()->fetchOne($select);
+        }
+        return $this->_customerIds[$email][$websiteId];
     }
 }
