Closed Bug 1429676 Opened 7 years ago Closed 7 years ago

[meta] Optimize callers of nsIEditActionListener methods

Categories

(Core :: DOM: Editor, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
Tracking Status
firefox59 --- affected

People

(Reporter: masayuki, Assigned: masayuki)

References

(Blocks 1 open bug)

Details

(Keywords: meta)

As far as my investigation, there are 4 active classes which implements nsIEditActionLisstener. 3 of them are our internal classes, HTMLEditRules, nsTextServicesDocument and mozInlineSpellChecker. The other is, ThunderHTMLedit addon. (Other addons are not available even on Thunderbird 52. So, we can ignore them.)

Nobody implements WillCreateNode, WillInsertNode, WillSplitNode, WillInsertText and WillDeleteText actually. So, we can just drop them simply.

ThunderHTMLedit implements all Did* methods. So, if we keep supporting it, we cannot remove any Did* methods. Otherwise, nobody implements DidDeleteSelection, so, we can drop this too. And if we can make some our classes register EditorBase directly, we can get rid of more methods.
I'm the author of ThunderHTMLedit and that's still working at TB 59 and I intend to maintain it.

Basically I'm listening to any changes in the document so that when I switch to the HTML view I know to regenerate the HTML. This is the add-on code:

  // nsIEditActionListener
  DidCreateNode:       function(tag, node, parent, position ) { this.Dirty(); },
  DidDeleteNode:       function(child)                        { this.Dirty(); },
  DidDeleteSelection:  function(selection)                    { this.Dirty(); this.Action(); },
  DidDeleteText:       function(textNode, offset, length)     { this.Dirty(); this.Action(); },
  DidInsertNode:       function(node, parent, position)       { this.Dirty(); },
  DidInsertText:       function(textNode, offset, string)     { this.Dirty(); this.Action(); },
  DidJoinNodes:        function(leftNode, rightNode, parent)  { this.Dirty(); },
  DidSplitNode:        function(existingRightNode, offset, newLeftNode) { this.Dirty(); },
  WillCreateNode:      function(tag, parent, position)        { },
  WillDeleteNode:      function(child)                        { },
  WillDeleteSelection: function(selection )                   { },
  WillDeleteText:      function(textNode, offset, length)     { },
  WillInsertNode:      function(node, parent, position)       { },
  WillInsertText:      function(textNode, offset, string)     { },
  WillJoinNodes:       function(leftNode,  rightNode, parent) { },
  WillSplitNode:       function(existingRightNode, offset)    { },

So is there any other or better way to get notified? Why do you think it's a good idea to remove a feature from a *toolbox*?

Note that the add-on where the ThunderHTMLcode was forked from, Stationery 0.8.6.2, has removed their home-grown HTML editor using nsIEditActionListener and switched to integrating Ace (https://ace.c9.io/) in their version 0.9.0.2. Ace doesn't use nsIEditActionListener, so perhaps it's about time to fork again and integrate Ace into ThunderHTMLedit as well.
(In reply to Jorg K (GMT+1) from comment #1)
> I'm the author of ThunderHTMLedit and that's still working at TB 59 and I
> intend to maintain it.

Yeah, therefore, I cced you.

> So is there any other or better way to get notified?

First of all, we still don't decide to remove all of them. If somebody still need them, we can keep only necessary methods.

On the other hand, your addon just observes any actions. Cannot use "input" event or mutation observer instead?

> Why do you think it's a
> good idea to remove a feature from a *toolbox*?

Currently, we call a set of Will and Did methods of edit action listeners every DOM change caused by edit action. Those methods are virtual call and we need to copy all listeners to local variable twice (one is for Will, the other is for Did) before loop to call a method and add all refcounters for guaranteeing the lifetime of the listeners. So these things really expensive. We want to reduce such cost for improving UI response.
Thanks for keeping me in the loop. Please go ahead as you deem fit, even with a complete removal. I'll find a way of adapting the add-on.
Keywords: meta
Summary: Get rid of nsIEditActionListener or some methods of it → Optimize callers of nsIEditActionListener
Summary: Optimize callers of nsIEditActionListener → Optimize callers of nsIEditActionListener methods
After fixing bug 1430021, bug 1430785 and bug 1430982, EditorBase never calls methods of nsIEditActionListener when any installed addons don't listen to edit actions and user doesn't highlight findbar's result. So, these series of bugs must improve the performance in most cases.
FYI: I'll land all patches after the merge for 60.
Thanks!
I was going to reply on dev.platform, and see that what conversation there has been is here.  I support removing this interface and the callbacks entirely; if it's not used in mozilla-central, we shouldn't maintain it.  There are some things that we can help comm-central maintain, for a short amount of time; and we can definitely try to find replacements (as Masayuki did -- thanks!); but there are lots of things that must be removed from mozilla-central, and we should do that as quickly and efficiently as we can.
(In reply to Nick Alexander :nalexander from comment #8)
> There are some things that we can help comm-central maintain, for a short
> amount of time; and we can definitely try to find replacements (as Masayuki
> did -- thanks!); but there are lots of things that must be removed from
> mozilla-central, and we should do that as quickly and efficiently as we can.

Yeah, but editor module is really important for both Thunderbird and Bluegriffon. Unless something blocks our improvements, we should keep to having such interfaces in editor.  Although we shouldn't use such slow path at runtime of Firefox as far as possible.
(In reply to Masayuki Nakano [:masayuki] (JST, +0900) from comment #9)
> (In reply to Nick Alexander :nalexander from comment #8)
> > There are some things that we can help comm-central maintain, for a short
> > amount of time; and we can definitely try to find replacements (as Masayuki
> > did -- thanks!); but there are lots of things that must be removed from
> > mozilla-central, and we should do that as quickly and efficiently as we can.
> 
> Yeah, but editor module is really important for both Thunderbird and
> Bluegriffon. Unless something blocks our improvements, we should keep to
> having such interfaces in editor.  Although we shouldn't use such slow path
> at runtime of Firefox as far as possible.

There are lots of things that are important for lots of XUL projects that consume Firefox.  They are going to have to find a way to not use XUL in the very near future.  In addition, Firefox shouldn't have the expense -- both at runtime but more importantly at maintenance time or creation time -- of two pathways.

In any case, you asked, and I responded as a voice on the extreme side of the continuum between "rip it out now" and "support it forever".  Somewhere in the middle, the right path for right now lies.  I'm sure you'll do a great job finding the right path :)
Priority: -- → P3
Ah, this should be marked as FIXED. Unless user shows the findbar and is using its highlight mode, editor won't use nsIEditActionListener to notify ending an edit action.
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Summary: Optimize callers of nsIEditActionListener methods → [meta] Optimize callers of nsIEditActionListener methods
You need to log in before you can comment on or make changes to this bug.