Skip to content

Instantly share code, notes, and snippets.

@zbraniecki
Created January 11, 2019 19:13
Show Gist options
  • Select an option

  • Save zbraniecki/3870157d26374ef79df0d4e1863f02a3 to your computer and use it in GitHub Desktop.

Select an option

Save zbraniecki/3870157d26374ef79df0d4e1863f02a3 to your computer and use it in GitHub Desktop.
Block Layout Perf Diff
diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -1343,7 +1343,8 @@ Document::Document(const char* aContentT
mThrowOnDynamicMarkupInsertionCounter(0),
mIgnoreOpensDuringUnloadCounter(0),
mDocLWTheme(Doc_Theme_Uninitialized),
- mSavedResolution(1.0f) {
+ mSavedResolution(1.0f),
+ mPendingInitialTranslation(false) {
MOZ_LOG(gDocumentLeakPRLog, LogLevel::Debug, ("DOCUMENT %p created", this));
SetIsInDocument();
@@ -3135,7 +3136,7 @@ void Document::LocalizationLinkAdded(Ele
// container is reached.
mL10nResources.AppendElement(href);
- SetInitialTranslationPending();
+ mPendingInitialTranslation = true;
}
}
@@ -3183,15 +3184,9 @@ void Document::TriggerInitialDocumentTra
}
}
-void Document::SetInitialTranslationPending() {
- MOZ_ASSERT(mParser, "This method should be called only during parsing.");
- if (mParser) {
- nsIContentSink* sink = mParser->GetContentSink();
- sink->SetInitialTranslationPending(true);
- }
-}
-
void Document::InitialDocumentTranslationCompleted() {
+ mPendingInitialTranslation = false;
+
nsCOMPtr<nsIContentSink> sink;
if (mParser) {
sink = mParser->GetContentSink();
@@ -3199,9 +3194,7 @@ void Document::InitialDocumentTranslatio
sink = do_QueryReferent(mWeakSink);
}
if (sink) {
- sink->SetInitialTranslationPending(false);
- } else {
- // What should we do here? Is it possible?
+ sink->InitialDocumentTranslationCompleted();
}
}
diff --git a/dom/base/Document.h b/dom/base/Document.h
--- a/dom/base/Document.h
+++ b/dom/base/Document.h
@@ -3406,19 +3406,6 @@ class Document : public nsINode,
void TriggerInitialDocumentTranslation();
/**
- * This method should be called once we encounter
- * the first indication that the document will need
- * to be localized before layout.
- *
- * This happens when the first localization link
- * is being parsed.
- *
- * This method is virtual so that XULDocument can
- * override it.
- */
- virtual void SetInitialTranslationPending();
-
- /**
* This method is called when the initial translation
* of the document is completed.
*
@@ -4461,9 +4448,13 @@ class Document : public nsINode,
// Pres shell resolution saved before entering fullscreen mode.
float mSavedResolution;
+ bool mPendingInitialTranslation;
+
public:
// Needs to be public because the bindings code pokes at it.
js::ExpandoAndGeneration mExpandoAndGeneration;
+
+ bool HasPendingInitialTranslation() { return mPendingInitialTranslation; }
};
NS_DEFINE_STATIC_IID_ACCESSOR(Document, NS_IDOCUMENT_IID)
diff --git a/dom/base/nsContentSink.cpp b/dom/base/nsContentSink.cpp
--- a/dom/base/nsContentSink.cpp
+++ b/dom/base/nsContentSink.cpp
@@ -95,8 +95,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
nsContentSink::nsContentSink()
- : mPendingInitialTranslation(false),
- mBackoffCount(0),
+ : mBackoffCount(0),
mLastNotificationTime(0),
mBeganUpdate(0),
mLayoutStarted(0),
@@ -1176,6 +1175,10 @@ void nsContentSink::StartLayout(bool aIg
return;
}
+ if (mDocument->HasPendingInitialTranslation()) {
+ return;
+ }
+
mDeferredLayoutStart = false;
// Notify on all our content. If none of our presshells have started layout
@@ -1530,11 +1533,8 @@ nsresult nsContentSink::WillParseImpl(vo
return NS_OK;
}
-void nsContentSink::SetInitialTranslationPendingImpl(bool aPending) {
- mPendingInitialTranslation = aPending;
- if (!aPending) {
- StartLayout(false);
- }
+void nsContentSink::InitialDocumentTranslationCompletedImpl() {
+ StartLayout(false);
}
void nsContentSink::WillBuildModelImpl() {
diff --git a/dom/base/nsContentSink.h b/dom/base/nsContentSink.h
--- a/dom/base/nsContentSink.h
+++ b/dom/base/nsContentSink.h
@@ -234,9 +234,7 @@ class nsContentSink : public nsICSSLoade
// URI format or of the form "//www.hostname.com" without a scheme.
void Preconnect(const nsAString& aHref, const nsAString& aCrossOrigin);
- // This allows the parser to block/unblock layout on pending
- // translation of the document.
- void SetInitialTranslationPendingImpl(bool aPending);
+ void InitialDocumentTranslationCompletedImpl();
protected:
// Tries to scroll to the URI's named anchor. Once we've successfully
@@ -251,8 +249,6 @@ class nsContentSink : public nsICSSLoade
static void NotifyDocElementCreated(Document* aDoc);
- bool mPendingInitialTranslation;
-
protected:
void FavorPerformanceHint(bool perfOverStarvation, uint32_t starvationDelay);
@@ -269,7 +265,7 @@ class nsContentSink : public nsICSSLoade
// Later on we might want to make this more involved somehow
// (e.g. stop waiting after some timeout or whatnot).
bool WaitForPendingItems() {
- return mPendingSheetCount > 0 || mPendingInitialTranslation;
+ return mPendingSheetCount > 0 || mDocument->HasPendingInitialTranslation();
}
void DoProcessLinkHeader();
diff --git a/dom/xml/nsXMLContentSink.cpp b/dom/xml/nsXMLContentSink.cpp
--- a/dom/xml/nsXMLContentSink.cpp
+++ b/dom/xml/nsXMLContentSink.cpp
@@ -1409,8 +1409,8 @@ nsresult nsXMLContentSink::AddText(const
return NS_OK;
}
-void nsXMLContentSink::SetInitialTranslationPending(bool aPending) {
- SetInitialTranslationPendingImpl(aPending);
+void nsXMLContentSink::InitialDocumentTranslationCompleted() {
+ InitialDocumentTranslationCompletedImpl();
}
void nsXMLContentSink::FlushPendingNotifications(FlushType aType) {
diff --git a/dom/xml/nsXMLContentSink.h b/dom/xml/nsXMLContentSink.h
--- a/dom/xml/nsXMLContentSink.h
+++ b/dom/xml/nsXMLContentSink.h
@@ -67,7 +67,7 @@ class nsXMLContentSink : public nsConten
NS_IMETHOD WillInterrupt(void) override;
NS_IMETHOD WillResume(void) override;
NS_IMETHOD SetParser(nsParserBase* aParser) override;
- virtual void SetInitialTranslationPending(bool aPending) override;
+ virtual void InitialDocumentTranslationCompleted() override;
virtual void FlushPendingNotifications(mozilla::FlushType aType) override;
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) override;
virtual nsISupports* GetTarget() override;
diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -450,12 +450,9 @@ void XULDocument::AddElementToDocumentPo
}
}
-void XULDocument::SetInitialTranslationPending() {
- mPendingInitialTranslation = true;
-}
-
void XULDocument::InitialDocumentTranslationCompleted() {
mPendingInitialTranslation = false;
+
DoneWalking();
}
diff --git a/dom/xul/XULDocument.h b/dom/xul/XULDocument.h
--- a/dom/xul/XULDocument.h
+++ b/dom/xul/XULDocument.h
@@ -76,7 +76,6 @@ class XULDocument final : public XMLDocu
virtual void EndLoad() override;
- virtual void SetInitialTranslationPending() override;
virtual void InitialDocumentTranslationCompleted() override;
// nsIMutationObserver interface
diff --git a/parser/html/nsHtml5TreeOpExecutor.cpp b/parser/html/nsHtml5TreeOpExecutor.cpp
--- a/parser/html/nsHtml5TreeOpExecutor.cpp
+++ b/parser/html/nsHtml5TreeOpExecutor.cpp
@@ -228,8 +228,8 @@ nsHtml5TreeOpExecutor::SetParser(nsParse
return NS_OK;
}
-void nsHtml5TreeOpExecutor::SetInitialTranslationPending(bool aPending) {
- SetInitialTranslationPendingImpl(aPending);
+void nsHtml5TreeOpExecutor::InitialDocumentTranslationCompleted() {
+ InitialDocumentTranslationCompletedImpl();
}
void nsHtml5TreeOpExecutor::FlushPendingNotifications(FlushType aType) {
diff --git a/parser/html/nsHtml5TreeOpExecutor.h b/parser/html/nsHtml5TreeOpExecutor.h
--- a/parser/html/nsHtml5TreeOpExecutor.h
+++ b/parser/html/nsHtml5TreeOpExecutor.h
@@ -135,7 +135,7 @@ class nsHtml5TreeOpExecutor final
*/
NS_IMETHOD SetParser(nsParserBase* aParser) override;
- virtual void SetInitialTranslationPending(bool aPending) override;
+ virtual void InitialDocumentTranslationCompleted() override;
/**
* No-op for backwards compat.
diff --git a/parser/htmlparser/nsIContentSink.h b/parser/htmlparser/nsIContentSink.h
--- a/parser/htmlparser/nsIContentSink.h
+++ b/parser/htmlparser/nsIContentSink.h
@@ -99,8 +99,6 @@ class nsIContentSink : public nsISupport
*/
NS_IMETHOD SetParser(nsParserBase* aParser) = 0;
- virtual void SetInitialTranslationPending(bool aPending) {}
-
/**
* Flush content so that the content model is in sync with the state
* of the sink.
@@ -132,6 +130,8 @@ class nsIContentSink : public nsISupport
* Posts a runnable that continues parsing.
*/
virtual void ContinueInterruptedParsingAsync() {}
+
+ virtual void InitialDocumentTranslationCompleted() {}
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIContentSink, NS_ICONTENT_SINK_IID)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment