Closed Bug 1497746 Opened 3 years ago Closed 3 years ago

Reduce footprint of TextEditor


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




Tracking Status
firefox64 --- wontfix
firefox65 --- fixed


(Reporter: masayuki, Assigned: masayuki)


(Blocks 1 open bug)



(6 files)

Currently, TextEditor size is 544 bytes. This is unfortunately larger than 512 bytes, which is allocated with 1024 bytes chunk.  So, for reducing memory size in web apps which have <input> element a lot, we need to reduce its memory size less than at least 500 bytes because we may need to add member urgently and that shouldn't cause crossing the border.

I'm working on bug 1465702 which allows some members which are necessary only when handling an edit action to move stack. That must help to fix this bug.
Priority: -- → P3
Assignee: nobody → masayuki
EditorBase::mTopLevelEditSubAction is set only by
EditorBase::OnStartToHandleTopLevelEditSubAction() and
EditorBase::OnEndToHandleTopLevelEditSubAction() and they are called only by

So, this is used only in stack when a public method of editor is called.
Therefore, we can move it into EditorBase::AutoEditActionDataSetter.  Then,
we can reduce heap allocation for editor instances.
EditorBase::mDirection is set and clear only when
EditorBase::AutoEditActionDataSetter::SetTopLevelEditSubAction().  So, the
direction is related to the top level edit sub action, and we can move it
into AutoEditActionDataSetter.

Note that except EditSubAction::eDeleteSelectedContent, the relation between
sub-action and direction is fixed so that this patch checks the relation with
MOZ_ASSERT.  If we could replace EditSubAction::eDeleteSelectedContent with
information of direction, we'd remove the new member of
AutoEditActionDataSetter, though.
EditorBase::mSavedSel is used only by EditorBase methods which are called only
by AutoSelectionRestorer.  Additionally, AutoSelectionRestorer requires
AutoEditActionDataSetter instance.  So, we don't need to keep create for
editor instance anymore.  And also we don't need to keep it in the cycle

Note that SelectionState class is also used by PlaceholderTransaction.
Therefore, we cannot make it MOZ_STACK_CLASS.
Similar to EditorBase::mSavedSel, we can move EditorBase::mRangeUpdater too
because of it's referred only when there is AutoEditActionDataSetter instance
so that it also does not need to be in the cycle collection.

And now, it can be marked as MOZ_STACK_CLASS and remove cycle collection
A lot of listeners are now notified with RefPtr for concrete classes.
Therefore, we can reduce size of arrays to listeners without damage for
the performance.
TextEditor instance is created per <input> element which has text editor and
<textarea> element.  Therefore, we should keep TextEditor slim as far as

Currently, TextEditor class size is 400 bytes on Win64.  So, we should keep
512 bytes border.
So, after landing those patches, there are 112 bytes for new members. I think that this is enough space. On the other hand, we can move PlaceholderTransaction related members into AutoEditActionDataSetter too. However, I don't work on them for now because we cannot reach next border, 256 bytes with the change. So, there is no merit to work on that and I don't have much time.
Pushed by
part 1: Move EditorBase::mTopLevelEditSubAction to EditorBase::AutoEditActionDataSetter r=m_kato
part 2: Move EditorBase::mDirection to EditorBase::AutoEditActionDataSetter r=m_kato
part 3: Move EditorBase::mSavedSel into AutoEditActionDataSetter r=m_kato
part 4: Move EditorBase::mRangeUpdater to AutoEditActionDataSetter r=m_kato
part 5: Make EditorBase not reserve array for its listeners unless listeners are important r=m_kato
part 6: Add static_assert for preventing TextEditor to grow up again r=m_kato
You need to log in before you can comment on or make changes to this bug.