diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php
index 7c150e9..8f031fa 100644
--- a/core/lib/Drupal/Core/Config/Config.php
+++ b/core/lib/Drupal/Core/Config/Config.php
@@ -342,11 +342,18 @@ public function load() {
   /**
    * Saves the configuration object.
    *
+   * @param callable|null|false $sorter
+   *   (optional) A callable which sorts the data before save. FALSE will
+   *   disable sorting. Defaults to NULL, therby using
+   *   Drupal\Core\Config\Config:sortByKey().
+   *
    * @return Drupal\Core\Config\Config
    *   The configuration object.
    */
-  public function save() {
-    $this->sortByKey($this->data);
+  public function save($sorter = NULL) {
+    if ($sorter !== FALSE) {
+      $this->data = call_user_func($sorter ? $sorter : array($this, 'sortByKey'), $this->data);
+    }
     $this->storage->write($this->name, $this->data);
     $this->isNew = FALSE;
     $this->notify('save');
@@ -379,14 +386,18 @@ public function rename($new_name) {
    *
    * @param array $data
    *   An associative array to sort recursively by key name.
+   *
+   * @return array
+   *   The sorted associative array.
    */
-  public function sortByKey(array &$data) {
+  public function sortByKey(array $data) {
     ksort($data);
     foreach ($data as &$value) {
       if (is_array($value)) {
-        $this->sortByKey($value);
+        $value = $this->sortByKey($value);
       }
     }
+    return $data;
   }
 
   /**
