Problem/Motivation
Drupal triggers behaviors on each Ajax changes. On the homepage, Drupal.behaviors.toggleEditMode.attach() called 13 times.
`Drupal.ajax.instances` defined inside the function and loop over on each call. It's about 70 loops in total on the homepage loading.
Proposed resolution
1. It doesn't reassign the value, we need not `filter` and then `forEach`. `filter` create a new ARRAY which uses extra memory.
2. Ideally, it should only execution after contextual links fully loaded or after Top left Toggle button is clicked.
3. Ideally, "fullscreen" should be returned from Ajax. (might be hack Drupal.Ajax to support data-progress-type)
4. Drupal has no 2-way data binding. If we can't do #3, I'd suggest changing the setting when you clicking the target edit area (here's what the #0 patch does)
Remaining tasks
- Review Patch
User interface changes
- NO
API changes
- NO
Data model changes
- NO
Comment | File | Size | Author |
---|---|---|---|
#28 | 2901667-nr-bot.txt | 132 bytes | needs-review-queue-bot |
#13 | jqueryparents.png | 249.03 KB | GrandmaGlassesRopeMan |
#13 | contextual.js_.png | 77.19 KB | GrandmaGlassesRopeMan |
#13 | 2901667-13.patch | 3.23 KB | GrandmaGlassesRopeMan |
#3 | 2901667-3.patch | 2.83 KB | droplet |
Comments
Comment #2
droplet CreditAttribution: droplet commented** Note: I don't familiar with OutSide_In :) And here's a quick patch in #0. I hope there's some better workaround :P
Comment #3
droplet CreditAttribution: droplet commentedwell. It can even more clean code
Comment #4
droplet CreditAttribution: droplet commentedI raise the priority since `Drupal.attachBehaviors` reattached 9 times on homepage (default installation profile). A huge performance impact
Comment #5
Wim LeersCan you quantify this?
Comment #6
tedbowThese 2 lines are not being replaced anywhere. We still need the behavior so I don't think this block of code can removed at all.
I manually tested and confirm that "active" block is not highlight with this patch. Which means we need a test for that since the patch passed.
Comment #7
GrandmaGlassesRopeManCan we also check for the existence of
instance.options.data.dialogOptions.outsideInActiveEditableId
to we can more strictly filter elements to avoid looking at potential duplicates?I think we need these.
Comment #8
droplet CreditAttribution: droplet commentedComment #9
tedbowChanging to new settings_tray.module component. @drpal thanks for script help! :)
Comment #10
tedbowNeeds reroll at least for changes in #2803375: Rename Outside-in module to "Settings Tray" for real
Comment #11
droplet CreditAttribution: droplet commentedRemove reroll since current patch doesn't work very well :)
Comment #12
tedbowI don't think we need the patch. I am not sure there is actually performance problem here.
From the Proposed solution:
We can't know when all contextual links are loaded. Ajax could add another part of the page when have new contextual links, correct?
Also the top edit button may never actually be clicked because click "Quick Edit" on any block will invoke edit mode
I don't see how we can not the event
drupalContextualLinkAdded
Seems like be a BC break now it would be using the default progress type for jQuery
Comment #13
GrandmaGlassesRopeManAlright. I'm not sure this is even needed anymore, but this is mostly a micro optimization.
This function,
prepareAjaxLinks()
appears to be fired 11 times viacontextual.js
The slowest part of this is the jQuery
.parents()
lookup.Comment #14
Wim Leersvs
Comment #15
droplet CreditAttribution: droplet commentedQuick response to #14
I didn't measure the time diff anyway. It's not so noticeable to human but developer would care. Time also affected by each behavior execution time. We have no long-running behaviors in CORE.
Before Patch:
simple math:
Drupal.behaviors attaches * trigger buttons number + re-attach trigger another round Drupal.behaviors attaches * trigger buttons number
more accurate:
I can't work out for it now and don't think really needed.
So with my original issue summary above, it was called 13 times and end up with 70 loops (It was logging with console.log)
On the AVG, the pages called Drupal.behaviors 30 times (I remembered nod_ was doing a roughly researching on this part somewhere)
70 / 13 * 30 ~= 160 loops. (actually it should be a non-linear equation)
After Patch:
my suggestion will turn into constant, single time.
Best case: no clicks, zero execution. 1 click, 1 execution. (It's not the Drupal-way. In Drupal, we always initialize everything at page load)
Better case: Drupal.behaviors attaches * trigger buttons number
** It may not correct with up-to-date code. I will re-evaluate it for sure! Thanks ALL!!
Comment #16
tedbowIf #13 approves the performance I am all for it. It doesn't need some the larger changes that were suggested in the proposed solution in the issue summary. Those other changes would require changes outside of this module I think.
Comment #21
apadernoComment #28
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.