diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php
index b67a37b..89acee7 100644
--- a/core/lib/Drupal/Core/Form/FormBuilder.php
+++ b/core/lib/Drupal/Core/Form/FormBuilder.php
@@ -787,7 +787,7 @@ public function doBuildForm($form_id, &$element, FormStateInterface &$form_state
 
       // Assign a decimal placeholder weight to preserve original array order.
       if (!isset($element[$key]['#weight'])) {
-        $element[$key]['#weight'] = $count/1000;
+        $element[$key]['#weight'] = $count;
       }
       else {
         // If one of the child elements has a weight then we will need to sort
diff --git a/core/lib/Drupal/Core/Render/Element.php b/core/lib/Drupal/Core/Render/Element.php
index eed5c30..0e1c50d 100644
--- a/core/lib/Drupal/Core/Render/Element.php
+++ b/core/lib/Drupal/Core/Render/Element.php
@@ -77,15 +77,29 @@ public static function children(array &$elements, $sort = FALSE) {
     $sort = isset($elements['#sorted']) ? !$elements['#sorted'] : $sort;
 
     // Filter out properties from the element, leaving only children.
-    $children = array();
+    $count = count($elements);
+    $child_weights = array();
+    $i = 0;
     $sortable = FALSE;
     foreach ($elements as $key => $value) {
       if ($key === '' || $key[0] !== '#') {
         if (is_array($value)) {
-          $children[$key] = $value;
           if (isset($value['#weight'])) {
+            if (!is_int($value['#weight'])) {
+                trigger_error(
+                    String::format('"@key" has an invalid weight. Only integer values are accepted.',
+                    array('@key' => $key)), E_USER_ERROR
+                );
+            }
+            $child_weights[$key] = $value['#weight'];
             $sortable = TRUE;
           }
+          else {
+            $child_weights[$key] = 0;
+          }
+          // Add a small number between 0 and 1 to keep the order of insertion
+          // of equal weight elements.
+          $child_weights[$key] += $i / $count;
         }
         // Only trigger an error if the value is not null.
         // @see http://drupal.org/node/1283892
@@ -93,21 +107,24 @@ public static function children(array &$elements, $sort = FALSE) {
           trigger_error(String::format('"@key" is an invalid render array key', array('@key' => $key)), E_USER_ERROR);
         }
       }
+      $i++;
     }
+
     // Sort the children if necessary.
     if ($sort && $sortable) {
-      uasort($children, 'Drupal\Component\Utility\SortArray::sortByWeightProperty');
+      asort($child_weights);
       // Put the sorted children back into $elements in the correct order, to
       // preserve sorting if the same element is passed through
       // \Drupal\Core\Render\Element::children() twice.
-      foreach ($children as $key => $child) {
+      foreach ($child_weights as $key => $weight) {
+        $value = $elements[$key];
         unset($elements[$key]);
-        $elements[$key] = $child;
+        $elements[$key] = $value;
       }
       $elements['#sorted'] = TRUE;
     }
 
-    return array_keys($children);
+    return array_keys($child_weights);
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Render/Element/Checkboxes.php b/core/lib/Drupal/Core/Render/Element/Checkboxes.php
index 1891ceb..10f2214 100644
--- a/core/lib/Drupal/Core/Render/Element/Checkboxes.php
+++ b/core/lib/Drupal/Core/Render/Element/Checkboxes.php
@@ -64,7 +64,7 @@ public static function processCheckboxes(&$element, FormStateInterface $form_sta
         // Maintain order of options as defined in #options, in case the element
         // defines custom option sub-elements, but does not define all option
         // sub-elements.
-        $weight += 0.001;
+        $weight ++;
 
         $element += array($key => array());
         $element[$key] += array(
diff --git a/core/lib/Drupal/Core/Render/Element/Radios.php b/core/lib/Drupal/Core/Render/Element/Radios.php
index 4b27b5a..538d0df 100644
--- a/core/lib/Drupal/Core/Render/Element/Radios.php
+++ b/core/lib/Drupal/Core/Render/Element/Radios.php
@@ -49,7 +49,7 @@ public static function processRadios(&$element, FormStateInterface $form_state,
         // Maintain order of options as defined in #options, in case the element
         // defines custom option sub-elements, but does not define all option
         // sub-elements.
-        $weight += 0.001;
+        $weight ++;
 
         $element += array($key => array());
         // Generate the parents as the autogenerator does, so we will have a
diff --git a/core/modules/comment/src/Tests/CommentPagerTest.php b/core/modules/comment/src/Tests/CommentPagerTest.php
index ca1c5a6..4104133 100644
--- a/core/modules/comment/src/Tests/CommentPagerTest.php
+++ b/core/modules/comment/src/Tests/CommentPagerTest.php
@@ -337,19 +337,19 @@ function testTwoPagers() {
     $this->assertRaw('Comment 1 on field comment');
     $this->assertRaw('Comment 1 on field comment_2');
     // Navigate to next page of field 1.
-    $this->clickLinkWithXPath('//a[@rel="next"]');
+    $this->clickLinkWithXPath('//section[contains(concat(" ", normalize-space(@class), " "), " field-name-comment ")]//a[@rel="next"]');
     // Check only one pager updated.
     $this->assertRaw('Comment 2 on field comment');
     $this->assertRaw('Comment 1 on field comment_2');
     // Return to page 1.
     $this->drupalGet('node/' . $node->id());
     // Navigate to next page of field 2.
-    $this->clickLinkWithXPath('//a[@rel="next"]', 1);
+    $this->clickLinkWithXPath('//section[contains(concat(" ", normalize-space(@class), " "), " field-name-comment-2 ")]//a[@rel="next"]');
     // Check only one pager updated.
     $this->assertRaw('Comment 1 on field comment');
     $this->assertRaw('Comment 2 on field comment_2');
     // Navigate to next page of field 1.
-    $this->clickLinkWithXPath('//a[@rel="next"]');
+    $this->clickLinkWithXPath('//section[contains(concat(" ", normalize-space(@class), " "), " field-name-comment ")]//a[@rel="next"]');
     // Check only one pager updated.
     $this->assertRaw('Comment 2 on field comment');
     $this->assertRaw('Comment 2 on field comment_2');
diff --git a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
index 7358f10..da99c17 100644
--- a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
+++ b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
@@ -206,7 +206,7 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
       '#type' => 'item',
       '#title' => t('Maximum image resolution'),
       '#element_validate' => array(array(get_class($this), 'validateResolution')),
-      '#weight' => 4.1,
+      '#weight' => 41,
       '#field_prefix' => '<div class="container-inline">',
       '#field_suffix' => '</div>',
       '#description' => t('The maximum allowed image size expressed as WIDTH×HEIGHT (e.g. 640×480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of <a href="@url">EXIF data</a> in the image.', array('@url' => 'http://en.wikipedia.org/wiki/Exchangeable_image_file_format')),
@@ -233,7 +233,7 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
       '#type' => 'item',
       '#title' => t('Minimum image resolution'),
       '#element_validate' => array(array(get_class($this), 'validateResolution')),
-      '#weight' => 4.2,
+      '#weight' => 42,
       '#field_prefix' => '<div class="container-inline">',
       '#field_suffix' => '</div>',
       '#description' => t('The minimum allowed image size expressed as WIDTH×HEIGHT (e.g. 640×480). Leave blank for no restriction. If a smaller image is uploaded, it will be rejected.'),
@@ -264,14 +264,14 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
       '#title' => t('Enable <em>Alt</em> field'),
       '#default_value' => $settings['alt_field'],
       '#description' => t('The alt attribute may be used by search engines, screen readers, and when the image cannot be loaded. Enabling this field is recommended'),
-      '#weight' => 9,
+      '#weight' => 90,
     );
     $element['alt_field_required'] = array(
       '#type' => 'checkbox',
       '#title' => t('<em>Alt</em> field required'),
       '#default_value' => $settings['alt_field_required'],
       '#description' => t('Making this field required is recommended.'),
-      '#weight' => 10,
+      '#weight' => 100,
       '#states' => array(
         'visible' => array(
           ':input[name="field[settings][alt_field]"]' => array('checked' => TRUE),
@@ -283,13 +283,13 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
       '#title' => t('Enable <em>Title</em> field'),
       '#default_value' => $settings['title_field'],
       '#description' => t('The title attribute is used as a tooltip when the mouse hovers over the image. Enabling this field is not recommended as it can cause problems with screen readers.'),
-      '#weight' => 11,
+      '#weight' => 110,
     );
     $element['title_field_required'] = array(
       '#type' => 'checkbox',
       '#title' => t('<em>Title</em> field required'),
       '#default_value' => $settings['title_field_required'],
-      '#weight' => 12,
+      '#weight' => 120,
       '#states' => array(
         'visible' => array(
           ':input[name="field[settings][title_field]"]' => array('checked' => TRUE),
diff --git a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php
index 33a64a7..a99ea45 100644
--- a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php
+++ b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php
@@ -218,7 +218,8 @@ public function testDefaultSearchPageOrdering() {
     $this->drupalGet('search');
     $elements = $this->xpath('//*[contains(@class, :class)]//a', array(':class' => 'tabs primary'));
     $this->assertIdentical((string) $elements[0]['href'], \Drupal::url('search.view_node_search'));
-    $this->assertIdentical((string) $elements[1]['href'], \Drupal::url('search.view_user_search'));
+    $this->assertIdentical((string) $elements[1]['href'], \Drupal::url('search.view_dummy_search_type'));
+    $this->assertIdentical((string) $elements[2]['href'], \Drupal::url('search.view_user_search'));
   }
 
   /**
diff --git a/core/modules/system/src/Tests/Menu/LocalTasksTest.php b/core/modules/system/src/Tests/Menu/LocalTasksTest.php
index 4edf30e..97f33ce 100644
--- a/core/modules/system/src/Tests/Menu/LocalTasksTest.php
+++ b/core/modules/system/src/Tests/Menu/LocalTasksTest.php
@@ -54,8 +54,8 @@ public function testPluginLocalTask() {
     $this->drupalGet(Url::fromRoute('menu_test.local_task_test_tasks_view'));
     $this->assertLocalTasks([
       ['menu_test.local_task_test_tasks_view', []],
-      ['menu_test.local_task_test_tasks_settings', []],
       ['menu_test.local_task_test_tasks_edit', []],
+      ['menu_test.local_task_test_tasks_settings', []],
     ]);
 
     // Ensure the view tab is active.
diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php
index 1205f28..e421965 100644
--- a/core/modules/views_ui/src/ViewEditForm.php
+++ b/core/modules/views_ui/src/ViewEditForm.php
@@ -1152,7 +1152,7 @@ public static function addMicroweights(&$build) {
     $count = 0;
     foreach (Element::children($build) as $key) {
       if (!isset($build[$key]['#weight'])) {
-        $build[$key]['#weight'] = $count/1000;
+        $build[$key]['#weight'] = $count;
       }
       static::addMicroweights($build[$key]);
       $count++;
diff --git a/core/tests/Drupal/Tests/Core/Asset/CssCollectionGrouperUnitTest.php b/core/tests/Drupal/Tests/Core/Asset/CssCollectionGrouperUnitTest.php
index 2d82c83..548c6eb 100644
--- a/core/tests/Drupal/Tests/Core/Asset/CssCollectionGrouperUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Asset/CssCollectionGrouperUnitTest.php
@@ -40,7 +40,7 @@ function testGrouper() {
         'group' => -100,
         'every_page' => TRUE,
         'type' => 'file',
-        'weight' => 0.012,
+        'weight' => 12,
         'media' => 'all',
         'preprocess' => TRUE,
         'data' => 'core/modules/system/system.base.css',
@@ -51,7 +51,7 @@ function testGrouper() {
         'group' => -100,
         'every_page' => TRUE,
         'type' => 'file',
-        'weight' => 0.013,
+        'weight' => 13,
         'media' => 'all',
         'preprocess' => TRUE,
         'data' => 'core/modules/system/system.theme.css',
@@ -61,7 +61,7 @@ function testGrouper() {
       'jquery.ui.core.css' => array(
         'group' => -100,
         'type' => 'file',
-        'weight' => 0.004,
+        'weight' => 4,
         'every_page' => FALSE,
         'media' => 'all',
         'preprocess' => TRUE,
@@ -73,7 +73,7 @@ function testGrouper() {
         'every_page' => TRUE,
         'group' => 0,
         'type' => 'file',
-        'weight' => 0.011,
+        'weight' => 11,
         'media' => 'all',
         'preprocess' => TRUE,
         'data' => 'core/modules/field/theme/field.css',
@@ -84,7 +84,7 @@ function testGrouper() {
         'every_page' => FALSE,
         'group' => 0,
         'type' => 'external',
-        'weight' => 0.009,
+        'weight' => 9,
         'media' => 'all',
         'preprocess' => TRUE,
         'data' => 'http://example.com/external.css',
@@ -96,7 +96,7 @@ function testGrouper() {
         'every_page' => TRUE,
         'media' => 'all',
         'type' => 'file',
-        'weight' => 0.001,
+        'weight' => 1,
         'preprocess' => TRUE,
         'data' => 'core/themes/bartik/css/base/elements.css',
         'browsers' => array('IE' => TRUE, '!IE' => TRUE),
@@ -107,7 +107,7 @@ function testGrouper() {
         'every_page' => TRUE,
         'media' => 'print',
         'type' => 'file',
-        'weight' => 0.003,
+        'weight' => 3,
         'preprocess' => TRUE,
         'data' => 'core/themes/bartik/css/print.css',
         'browsers' => array('IE' => TRUE, '!IE' => TRUE),
diff --git a/core/tests/Drupal/Tests/Core/Render/ElementTest.php b/core/tests/Drupal/Tests/Core/Render/ElementTest.php
index 20ac844..969bc97 100644
--- a/core/tests/Drupal/Tests/Core/Render/ElementTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/ElementTest.php
@@ -89,6 +89,18 @@ public function testChildren() {
 
     $expected = array('child2', 'child1', 'child3');
     $this->assertSame($expected, Element::children($element_no_weight, TRUE));
+
+    // The order of children with same weight should be preserved.
+    $element_mixed_weight = array(
+      'child5' => array('#weight' => 10),
+      'child3' => array('#weight' => -10),
+      'child1' => array(),
+      'child4' => array('#weight' => 10),
+      'child2' => array(),
+    );
+
+    $expected = array('child3', 'child1', 'child2', 'child5', 'child4');
+    $this->assertSame($expected, Element::children($element_mixed_weight, TRUE));
   }
 
   /**
@@ -105,6 +117,41 @@ public function testInvalidChildren() {
   }
 
   /**
+   * Data provider for testInvalidChildrenWeights .
+   *
+   * @return array
+   */
+  public function InvalidChildWeightProvider() {
+    return array(
+      array(0.1),
+      array('invalid weight'),
+      array(new \stdClass())
+    );
+  }
+
+  /**
+   * Test the children() method with invalid parameters.
+   *
+   * @dataProvider InvalidChildWeightProvider
+   * @expectedException \PHPUnit_Framework_Error
+   * @expectedExceptionMessage "invalidChild" has an invalid weight
+   *
+   * $weight
+   *  An invalid element weight sent by data provider.
+   */
+  public function testInvalidChildrenWeights($weight) {
+    if (is_int($weight)) {
+      $this->markTestSkipped('Invalid parameter. $weight should not be an integer.');
+    }
+    $element = array(
+      'invalidChild' => array('#weight' => $weight),
+      'child2' => array('#weight' => 1),
+      'child3' => array()
+    );
+    Element::children($element);
+  }
+
+  /**
    * Tests the children() method with an ignored key/value pair.
    */
   public function testIgnoredChildren() {
