Problem/Motivation

The search links are populated whenever the admin_toolbar_search.js file is loaded.

I timed the $('.toolbar-tray a[data-drupal-link-system-path]').each(function () {}); loop function by using the js .time() function and found out that it takes approx 40-45ms to complete. That execution time can be defferred to a later stage, when the search bar is actually displayed. In this case we can boost our loading time performance and not block the thread with this function.

Proposed resolution

I suggest we add helper function for that and call it only when necessary - when the search bar is visible or when it's expanded.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sasanikolic created an issue. See original summary.

sasanikolic’s picture

Status: Active » Needs review
FileSize
2.12 KB

Here is the proposed patch with the improvement.

miro_dietiker’s picture

+++ b/js/admin_toolbar_search.js
@@ -155,6 +145,26 @@
+            $self.links.push({

From reading, i think this currently means that if you enter the search box twice, you will push each URL twice, and more...

Also it means each time you enter, the 40ms are spent again.

We should limit this to a single init execution only.

Or am i maybe wrong?

sasanikolic’s picture

+++ b/js/admin_toolbar_search.js
@@ -155,6 +145,26 @@
+      if ($self.links.length === 0) {

@miro_dietiker That's why I added this check here. If it's already populated, the code will not execute again.

Berdir’s picture

+++ b/js/admin_toolbar_search.js
@@ -155,6 +145,26 @@
+            $self.links.push({
+              'value': $(this).attr('href'),
+              'label': label + ' ' + $(this).attr('href'),
+              'labelRaw': label

can we get the attribute directly from this instead of going through jquery again? that could remove quite a bit of overhead I imagine?

sasanikolic’s picture

I noticed the duplicated admin_toolbar_search.js and opened a followup for that: .

Moved the code to the right file now and updated value and label to get the href using javascript instead of jquery.

adriancid’s picture

Status: Needs review » Fixed

Thanks

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.