Title says it all.

Based on feedback from Piotrek Koszuliński (CKEditor developer): they expressed concern that it does get called very, very often and that that our listener may lead to performance problems.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nod_’s picture

Issue tags: +JavaScript

tag

Reinmar’s picture

Issue tags: -JavaScript

My concern was that in case of 1:1 relation between CKEditor's #change event and Drupal's onChange, it may happen that e.g. content is being sent to server too often. However, I don't know how you use onChange, so I may be wrong. If a debouncer is meant to be used inside onChange's listener, then everything will be fine.

My second concern is that the editor.getData() is called on every #change. Getting data isn't a lightweight process - there's a parsing, filtering, processing, writing involved, so it's pretty heavy. It won't kill browser of course, but it may be unnecessary. Especially if callback's argument isn't then used.

I also noticed that if multiple listeners are added using onChange the editor.getData() will be called multiple times (once per every listener) on every #change. This may in fact overheat browser in case of dozens of listeners.

Wim Leers’s picture

Issue tags: +JavaScript

Great feedback, and great catch wrt the multiple listeners!

Wim Leers’s picture

Status: Active » Needs review
FileSize
2.42 KB

Please review — not sure if this is the best or most elegant way to support multiple callbacks.

Wim Leers’s picture

nod_ said in chat that:

  • The queueing of callbacks to ensure editor.getData() is called only once for all callbacks (if there are multiple callbacks) is not yet justified; if it turns out to be a performance problem in the future, we can still change this. (After all, that wouldn't be an API change.)
  • debounce(function changeHandler() { can cause problems — I added it to make stack traces less anonymous, which I know he likes, but apparently this is problematic too. ("named closures do weird things sometimes", he said.) Easy change.

Patch rerolled to address that.

Wim Leers’s picture

nod_ noticed a small pre-existing problem that should be fixed as part of this patch: ckeditor.js uses jQuery, but that dependency is not declared in the library definition.

nod_’s picture

Status: Needs review » Reviewed & tested by the community

Straightforward, that works, thanks :)

nod_’s picture

Issue summary: View changes

Updated issue summary.

Wim Leers’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: ckeditor_debounce_onchange-2064063-6.patch, failed testing.

Wim Leers’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 6: ckeditor_debounce_onchange-2064063-6.patch, failed testing.

Wim Leers’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 6: ckeditor_debounce_onchange-2064063-6.patch, failed testing.

Wim Leers’s picture

Status: Needs work » Needs review
Wim Leers’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

On the 4th try no more false negatives — yay! Back to RTBC. (I just wanted to confirm that the patch still applied.)

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Thanks. Committed to 8.x.

Status: Fixed » Closed (fixed)

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