Skip to main content

Magento 2: How an Excessive Customer Attribute Sort Order Causes the Admin Customer Save to Freeze

Magento 2: How an Excessive Customer Attribute Sort Order Causes the Admin Customer Save to Freeze

1. Problem Overview

We encountered a significant performance issue in Magento 2 when saving a customer from the Admin panel. Clicking either the Save Customer or Save and Continue Edit button caused the browser to become unresponsive for several minutes before the customer was successfully saved.

The following symptoms were observed:

  • The Magento Admin page became completely unresponsive.
  • The browser displayed a "This page isn't responding" warning.
  • No customer save request appeared immediately in the browser's Network tab.
  • The customer was eventually saved successfully.
  • The issue occurred repeatedly when saving customer information.

2. Initial Investigation

Initially, several potential causes were considered, including:

  • Magento Admin usage tracking and external analytics requests.
  • Custom Magento extensions.
  • RabbitMQ connection timeouts.
  • Database performance and locking issues.
  • PHP-FPM and server-side processing.
  • Magento JavaScript form validation.

However, the absence of a customer save request in the browser's Network tab indicated that the delay was occurring before the request reached the Magento backend.

This allowed us to focus our investigation on the Magento Admin JavaScript layer rather than the server infrastructure.

3. Identifying the JavaScript Performance Bottleneck

Using the browser's Developer Tools Performance profiler, we investigated the JavaScript execution triggered by clicking the Save button.

The investigation identified the following Magento UI component function as the primary performance bottleneck:

_isChildrenHasErrors()

The function is located in the following Magento core file:

vendor/magento/module-ui/view/base/web/js/form/components/fieldset.js

The relevant implementation was:


_isChildrenHasErrors: function (hasErrors, container) {
    var self = this;

    if (hasErrors === false && container.hasOwnProperty('elems')) {
        hasErrors = container.elems.some('error');

        if (hasErrors === false && container.hasOwnProperty('_elems')) {
            container._elems.forEach(function (child) {
                if (hasErrors === false) {
                    hasErrors = self._isChildrenHasErrors(hasErrors, child);
                }
            });
        }
    }

    return hasErrors;
},
    

This function recursively checks Magento UI components and their children for validation errors before the form is submitted.

4. Measuring the Performance Issue

We temporarily instrumented the JavaScript function using the browser Console to measure its execution time and the number of calls made during a single customer save operation.

The following results were recorded:

Performance Metric

Measured Result

Total recursive function calls

2,190

Top-level fieldset validation calls

73

Average validation time

Approximately 1.09 seconds

Total fieldset validation time

79.73 seconds

Error cache resynchronizations

0

Further investigation identified the specific Magento UI fieldset responsible for the delay:

customer_form.areas.customer.customer

This fieldset represents the main customer account information section in the Magento Admin customer edit form.

5. Discovering the Root Cause

Using Magento's JavaScript UI Registry, we inspected the internal structure of the affected customer fieldset.

The following diagnostic code was executed in the browser Console:


require(['uiRegistry'], function (registry) {
    var fieldset = registry.get(
        'customer_form.areas.customer.customer'
    );

    console.log({
        actualComponents: fieldset.elems().length,
        internalArrayLength: fieldset._elems.length
    });

    console.log('Internal collection:', fieldset._elems);
});
    

The results revealed an unexpected difference:

Collection

Length

Actual customer components

27

Internal JavaScript array

100,000,002

Although the customer form contained only 27 direct UI components, Magento's internal array had a length exceeding 100 million positions.

Further inspection revealed that a custom customer attribute named customer_portal_login_link was responsible.


Attribute: customer_portal_login_link
Sort Order: 99999999
Internal Array Index: 100000001
    

6. Why an Excessive Sort Order Causes This Problem

Magento UI components use the sort order of elements when organizing their internal component collections.

In this implementation, the sort order influences the position of components within an internal JavaScript array named _elems.

Under normal circumstances, sort order values might look like this:


First Name:                 10
Last Name:                  20
Email:                      30
Custom Attribute:          400
    

However, the problematic attribute was configured as follows:


Customer Portal Login Link: 99999999
    

This resulted in the creation of a massive sparse JavaScript array. A sparse array contains a small number of actual elements distributed across a potentially very large range of array indexes.

Although JavaScript does not necessarily allocate memory for every empty position, certain array operations can become extremely expensive when the array length is excessively large.

During customer form validation, Magento executes the following operation:

container._elems.forEach(function (child) { ... });

In our environment, traversing the oversized sparse array took approximately 1.09 seconds per validation call.

Since Magento performed 73 top-level validation calls during a single customer save, the accumulated execution time reached approximately 80 seconds.

This processing occurred synchronously on the browser's main JavaScript thread, preventing the browser from responding to user interactions and delaying the actual customer save request.

7. Confirming the Incorrect Database Configuration

Magento stores customer attribute sort order values in the customer_eav_attribute database table.

We executed the following SQL query to verify the configuration:


SELECT
    ea.attribute_id,
    ea.attribute_code,
    cea.sort_order
FROM eav_attribute AS ea
INNER JOIN customer_eav_attribute AS cea
    ON cea.attribute_id = ea.attribute_id
WHERE ea.attribute_code = 'customer_portal_login_link';
    

The query returned the following result:

Attribute ID

Attribute Code

Sort Order

201

customer_portal_login_link

99999999

This confirmed that the excessive sort order originated from the stored customer attribute configuration.

8. Implementing the Solution

The solution was to replace the excessively large sort order with a reasonable value.

In our environment, the other customer attributes had positions below 400. Therefore, we selected 400 to keep the custom attribute at the bottom of the customer form.

After taking the appropriate database backup, the following SQL statement can be used to correct the configuration:


UPDATE customer_eav_attribute AS cea
INNER JOIN eav_attribute AS ea
    ON cea.attribute_id = ea.attribute_id
SET cea.sort_order = 400
WHERE ea.attribute_code = 'customer_portal_login_link'
AND cea.sort_order = 99999999;
    

After updating the database, clean the relevant Magento caches:

php bin/magento cache:clean config eav

Refresh the Magento Admin customer edit page and test the customer save operation again.

In our case, correcting the sort order resolved the customer save performance issue and eliminated the browser freeze.

No changes to the following components were required:

  • Magento core JavaScript files.
  • PHP-FPM configuration.
  • Database server configuration.
  • RabbitMQ configuration.
  • Magento dependency injection configuration.
  • Magento form validation logic.

9. Preventing the Issue in Other Magento Installations

To identify other customer attributes with potentially problematic sort order values, execute the following SQL query:


SELECT
    ea.attribute_id,
    ea.attribute_code,
    cea.sort_order
FROM customer_eav_attribute AS cea
INNER JOIN eav_attribute AS ea
    ON ea.attribute_id = cea.attribute_id
WHERE cea.sort_order > 10000
ORDER BY cea.sort_order DESC;
    

The threshold of 10,000 is a recommended diagnostic threshold, not an official Magento framework limitation.

Each returned attribute should be reviewed individually before modifying its sort order.

Custom extension source code should also be reviewed for excessively large sort order configurations.


grep -Rn '99999999' app/code/ vendor/ \
    --include='*.php' \
    --include='*.xml' 2>/dev/null
    

10. Recommended Development Practices

When creating custom Magento customer attributes or UI components, developers should use reasonable sort order values rather than excessively large numbers intended to force a component to the bottom of a form.

The following ranges can be adopted as development conventions:

Sort Order Range

Recommended Usage

10 - 100

Standard fields

100 - 500

Custom fields

500 - 1000

Additional custom fields

1000 - 2000

Fields intended to appear at the bottom

These ranges are suggested development conventions and should be adapted to the existing component configuration.

For a permanent solution, the extension responsible for creating the customer attribute should also be corrected. A Magento data patch can be introduced to update the sort order automatically in existing installations.

11. Conclusion

This investigation demonstrates how a seemingly harmless customer attribute configuration can introduce a significant performance issue in Magento 2.

An excessively large sort order caused Magento to create a sparse JavaScript array containing more than 100 million positions, despite the customer form containing only 27 direct components.

Repeated recursive validation of this array blocked the browser's main JavaScript thread for approximately 80 seconds during each customer save operation.

By combining browser performance profiling, JavaScript diagnostics, Magento UI component inspection, and database analysis, we were able to identify the root cause and resolve the issue through a simple customer attribute configuration correction.

The key takeaway is that Magento sort order values should remain within reasonable ranges, as excessively large values can have unintended consequences on JavaScript performance and the responsiveness of the Magento Admin interface. 

Tags

↑