Reduce footprint of TextEditor

RESOLVED FIXED in Firefox 65

Status

()

enhancement
P3
normal
RESOLVED FIXED
11 months ago
9 months ago

People

(Reporter: masayuki, Assigned: masayuki)

Tracking

(Blocks 1 bug)

Trunk
mozilla65
x86_64
All
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox64 wontfix, firefox65 fixed)

Details

Attachments

(6 attachments)

47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
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
EditorBase::mTopLevelEditSubAction is set only by
EditorBase::OnStartToHandleTopLevelEditSubAction() and
EditorBase::OnEndToHandleTopLevelEditSubAction() and they are called only by
AutoTopLevelEditSubActionNotifier().

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
collection.

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
support.
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
possible.

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 masayuki@d-toybox.com:
https://hg.mozilla.org/integration/autoland/rev/6c108d9038c3
part 1: Move EditorBase::mTopLevelEditSubAction to EditorBase::AutoEditActionDataSetter r=m_kato
https://hg.mozilla.org/integration/autoland/rev/097a6db49477
part 2: Move EditorBase::mDirection to EditorBase::AutoEditActionDataSetter r=m_kato
https://hg.mozilla.org/integration/autoland/rev/465ebb044ee1
part 3: Move EditorBase::mSavedSel into AutoEditActionDataSetter r=m_kato
https://hg.mozilla.org/integration/autoland/rev/ceb75e2e0421
part 4: Move EditorBase::mRangeUpdater to AutoEditActionDataSetter r=m_kato
https://hg.mozilla.org/integration/autoland/rev/324232a1330c
part 5: Make EditorBase not reserve array for its listeners unless listeners are important r=m_kato
https://hg.mozilla.org/integration/autoland/rev/fb45231e386d
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.