Closed Bug 1360137 Opened 2 years ago Closed 2 years ago

Small optimize of TextEditor::OutputToString

Categories

(Core :: Editor, enhancement, P1)

55 Branch
enhancement

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: m_kato, Assigned: m_kato)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

From profiling of TextEditor::OutputToString

- QI from nsIDOMDocument to nsIDocument is 50% of nsDocumentEncoder.  We can use nsIDocuemnt directly.
- Most of WillOutputText is ToLowerCase.  We can use LowerCaseEqualsLiteral instead.

So we can be improve 5-10% of this.
Summary: Optimize TextEditor::OutputToString → Small optimize of TextEditor::OutputToString
Blocks: 1346723
Comment on attachment 8862327 [details]
Bug 1360137 - Part 2. Reduce QueryInterface by NativeInit.

https://reviewboard.mozilla.org/r/134260/#review137222

::: editor/libeditor/TextEditor.cpp:1194
(Diff revision 1)
>      mCachedDocumentEncoderType = aFormatType;
>    } else {
>      docEncoder = mCachedDocumentEncoder;
>    }
>  
> -  nsCOMPtr<nsIDOMDocument> domDoc = do_QueryReferent(mDocWeak);
> +  nsCOMPtr<nsIDocument> doc = GetDocument();

I know QI is slow, but how about do_QueryReferent()? If it's slow, cannot editor improve it more? (because a lot of code refers GetDocument(), etc.)
Attachment #8862327 - Flags: review?(masayuki) → review+
(In reply to Masayuki Nakano [:masayuki] (JST, +0900) from comment #4)

> I know QI is slow, but how about do_QueryReferent()? If it's slow, cannot
> editor improve it more? (because a lot of code refers GetDocument(), etc.)

do_QueryReference uses QI, it is slow too.  Humm, we can improve it by using inline for it and as parameter (In this case, GetDocumentCharset in OutputToString gets nsIDocument again.).  OK, I will file a new bug for it.
(In reply to Makoto Kato [:m_kato] (PTO: 4/30-5/5) from comment #5)
> (In reply to Masayuki Nakano [:masayuki] (JST, +0900) from comment #4)
> 
> > I know QI is slow, but how about do_QueryReferent()? If it's slow, cannot
> > editor improve it more? (because a lot of code refers GetDocument(), etc.)
> 
> do_QueryReference uses QI, it is slow too.  Humm, we can improve it by using
> inline for it and as parameter (In this case, GetDocumentCharset in
> OutputToString gets nsIDocument again.).  OK, I will file a new bug for it.

If nsWeakReference can have a method to check if mReferent is nullptr, then, perhaps, EditorBase can cache the pointer safely. If we can do that, we can improve the performance of any places which use mDocWeak, mPlaceHolderTxn and mSelConWeak.
Pushed by kwierso@gmail.com:
https://hg.mozilla.org/mozilla-central/rev/758999057396
Part 1. Use LowerCaseEqualsLiteral instead of ToLowerCase. r=masayuki
https://hg.mozilla.org/mozilla-central/rev/2c8e1d8ad8eb
Part 2. Reduce QueryInterface by NativeInit. r=masayuki
https://hg.mozilla.org/mozilla-central/rev/758999057396
https://hg.mozilla.org/mozilla-central/rev/2c8e1d8ad8eb
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.