commit e3efe1488ded894a6e3f6827b2aff0dc7b6a4066
parent 7392283b7e45201309878b5a48c02c87d0b6b7d8
Author: Nazım Can Altınova <canaltinova@gmail.com>
Date: Fri, 17 Oct 2025 11:04:03 +0000
Bug 1994144 - Use static atoms directly for PerformanceEntry types r=jlink,smaug
Previously we were passing strings to the constructor for
PerformanceEntry types, but we don't need that since we know them for
sure during the compile time. It makes it easier to use the static
atoms, and they should be faster than the previous code.
Differential Revision: https://phabricator.services.mozilla.com/D268543
Diffstat:
12 files changed, 30 insertions(+), 23 deletions(-)
diff --git a/dom/performance/LargestContentfulPaint.cpp b/dom/performance/LargestContentfulPaint.cpp
@@ -16,6 +16,7 @@
#include "mozilla/dom/Element.h"
#include "mozilla/nsVideoFrame.h"
#include "nsContentUtils.h"
+#include "nsGkAtoms.h"
#include "nsLayoutUtils.h"
#include "nsRFPService.h"
@@ -59,7 +60,7 @@ LargestContentfulPaint::LargestContentfulPaint(
const Maybe<TimeStamp>& aLoadTime, const unsigned long aSize, nsIURI* aURI,
Element* aElement, bool aShouldExposeRenderTime)
: PerformanceEntry(aPerformance->GetParentObject(), u""_ns,
- kLargestContentfulPaintName),
+ nsGkAtoms::largestContentfulPaint),
mPerformance(aPerformance),
mRenderTime(aRenderTime),
mLoadTime(aLoadTime),
diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp
@@ -183,15 +183,15 @@ void Performance::GetEntries(nsTArray<RefPtr<PerformanceEntry>>& aRetval) {
void Performance::GetEntriesByType(
const nsAString& aEntryType, nsTArray<RefPtr<PerformanceEntry>>& aRetval) {
- if (aEntryType.EqualsLiteral("resource")) {
+ RefPtr<nsAtom> entryType = NS_Atomize(aEntryType);
+ if (entryType == nsGkAtoms::resource) {
aRetval = mResourceEntries.Clone();
return;
}
aRetval.Clear();
- if (aEntryType.EqualsLiteral("mark") || aEntryType.EqualsLiteral("measure")) {
- RefPtr<nsAtom> entryType = NS_Atomize(aEntryType);
+ if (entryType == nsGkAtoms::mark || entryType == nsGkAtoms::measure) {
for (PerformanceEntry* entry : mUserEntries) {
if (entry->GetEntryType() == entryType) {
aRetval.AppendElement(entry);
diff --git a/dom/performance/PerformanceEntry.cpp b/dom/performance/PerformanceEntry.cpp
@@ -21,10 +21,8 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformanceEntry)
NS_INTERFACE_MAP_END
PerformanceEntry::PerformanceEntry(nsISupports* aParent, const nsAString& aName,
- const nsAString& aEntryType)
- : mParent(aParent),
- mName(NS_Atomize(aName)),
- mEntryType(NS_Atomize(aEntryType)) {}
+ const nsStaticAtom* aEntryType)
+ : mParent(aParent), mName(NS_Atomize(aName)), mEntryType(aEntryType) {}
PerformanceEntry::~PerformanceEntry() = default;
diff --git a/dom/performance/PerformanceEntry.h b/dom/performance/PerformanceEntry.h
@@ -25,7 +25,7 @@ class PerformanceEntry : public nsISupports, public nsWrapperCache {
public:
PerformanceEntry(nsISupports* aParent, const nsAString& aName,
- const nsAString& aEntryType);
+ const nsStaticAtom* aEntryType);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(PerformanceEntry)
@@ -47,10 +47,9 @@ class PerformanceEntry : public nsISupports, public nsWrapperCache {
}
const nsAtom* GetEntryType() const { return mEntryType; }
+ const nsStaticAtom* GetEntryTypeAsStaticAtom() const { return mEntryType; }
- void SetEntryType(const nsAString& aEntryType) {
- mEntryType = NS_Atomize(aEntryType);
- }
+ void SetEntryType(nsStaticAtom* aEntryType) { mEntryType = aEntryType; }
virtual DOMHighResTimeStamp StartTime() const { return 0; }
@@ -80,7 +79,7 @@ class PerformanceEntry : public nsISupports, public nsWrapperCache {
private:
nsCOMPtr<nsISupports> mParent;
RefPtr<nsAtom> mName;
- RefPtr<nsAtom> mEntryType;
+ const nsStaticAtom* mEntryType;
};
// Helper classes
diff --git a/dom/performance/PerformanceEventTiming.cpp b/dom/performance/PerformanceEventTiming.cpp
@@ -19,6 +19,7 @@
#include "mozilla/dom/Performance.h"
#include "mozilla/dom/PerformanceEventTimingBinding.h"
#include "nsContentUtils.h"
+#include "nsGkAtoms.h"
#include "nsIDocShell.h"
namespace mozilla::dom {
@@ -37,7 +38,8 @@ PerformanceEventTiming::PerformanceEventTiming(Performance* aPerformance,
const TimeStamp& aStartTime,
bool aIsCancelable,
EventMessage aMessage)
- : PerformanceEntry(aPerformance->GetParentObject(), aName, u"event"_ns),
+ : PerformanceEntry(aPerformance->GetParentObject(), aName,
+ nsGkAtoms::event),
mPerformance(aPerformance),
mProcessingStart(aPerformance->NowUnclamped()),
mProcessingEnd(0),
@@ -51,7 +53,7 @@ PerformanceEventTiming::PerformanceEventTiming(
const PerformanceEventTiming& aEventTimingEntry)
: PerformanceEntry(aEventTimingEntry.mPerformance->GetParentObject(),
nsDependentAtomString(aEventTimingEntry.GetName()),
- nsDependentAtomString(aEventTimingEntry.GetEntryType())),
+ aEventTimingEntry.GetEntryTypeAsStaticAtom()),
mPerformance(aEventTimingEntry.mPerformance),
mProcessingStart(aEventTimingEntry.mProcessingStart),
mProcessingEnd(aEventTimingEntry.mProcessingEnd),
diff --git a/dom/performance/PerformanceMainThread.cpp b/dom/performance/PerformanceMainThread.cpp
@@ -326,7 +326,7 @@ void PerformanceMainThread::DispatchPendingEventTimingEntries() {
if (StaticPrefs::dom_performance_event_timing_enable_interactionid()) {
if (!mHasDispatchedInputEvent && entry->InteractionId() != 0) {
mFirstInputEvent = entry->Clone();
- mFirstInputEvent->SetEntryType(u"first-input"_ns);
+ mFirstInputEvent->SetEntryType(nsGkAtoms::firstInput);
QueueEntry(mFirstInputEvent);
SetHasDispatchedInputEvent();
}
@@ -335,7 +335,7 @@ void PerformanceMainThread::DispatchPendingEventTimingEntries() {
switch (entry->GetMessage()) {
case ePointerDown: {
mPendingPointerDown = entry->Clone();
- mPendingPointerDown->SetEntryType(u"first-input"_ns);
+ mPendingPointerDown->SetEntryType(nsGkAtoms::firstInput);
break;
}
case ePointerUp: {
@@ -351,7 +351,7 @@ void PerformanceMainThread::DispatchPendingEventTimingEntries() {
case eKeyDown:
case eMouseDown: {
mFirstInputEvent = entry->Clone();
- mFirstInputEvent->SetEntryType(u"first-input"_ns);
+ mFirstInputEvent->SetEntryType(nsGkAtoms::firstInput);
QueueEntry(mFirstInputEvent);
SetHasDispatchedInputEvent();
break;
diff --git a/dom/performance/PerformanceMark.cpp b/dom/performance/PerformanceMark.cpp
@@ -12,6 +12,7 @@
#include "mozilla/dom/PerformanceBinding.h"
#include "mozilla/dom/PerformanceMarkBinding.h"
#include "nsContentUtils.h"
+#include "nsGkAtoms.h"
using namespace mozilla::dom;
@@ -19,7 +20,7 @@ PerformanceMark::PerformanceMark(nsISupports* aParent, const nsAString& aName,
DOMHighResTimeStamp aStartTime,
const JS::Handle<JS::Value>& aDetail,
DOMHighResTimeStamp aUnclampedStartTime)
- : PerformanceEntry(aParent, aName, u"mark"_ns),
+ : PerformanceEntry(aParent, aName, nsGkAtoms::mark),
mStartTime(aStartTime),
mDetail(aDetail),
mUnclampedStartTime(aUnclampedStartTime) {
diff --git a/dom/performance/PerformanceMeasure.cpp b/dom/performance/PerformanceMeasure.cpp
@@ -8,6 +8,7 @@
#include "MainThreadUtils.h"
#include "mozilla/dom/PerformanceMeasureBinding.h"
+#include "nsGkAtoms.h"
using namespace mozilla::dom;
@@ -16,7 +17,7 @@ PerformanceMeasure::PerformanceMeasure(nsISupports* aParent,
DOMHighResTimeStamp aStartTime,
DOMHighResTimeStamp aEndTime,
const JS::Handle<JS::Value>& aDetail)
- : PerformanceEntry(aParent, aName, u"measure"_ns),
+ : PerformanceEntry(aParent, aName, nsGkAtoms::measure),
mStartTime(aStartTime),
mDuration(aEndTime - aStartTime),
mDetail(aDetail) {
diff --git a/dom/performance/PerformanceNavigationTiming.h b/dom/performance/PerformanceNavigationTiming.h
@@ -46,7 +46,7 @@ class PerformanceNavigationTiming final : public PerformanceResourceTiming {
Performance* aPerformance, const nsAString& aName)
: PerformanceResourceTiming(std::move(aPerformanceTiming), aPerformance,
aName) {
- SetEntryType(u"navigation"_ns);
+ SetEntryType(nsGkAtoms::navigation);
SetInitiatorType(u"navigation"_ns);
}
diff --git a/dom/performance/PerformancePaintTiming.cpp b/dom/performance/PerformancePaintTiming.cpp
@@ -9,6 +9,7 @@
#include "MainThreadUtils.h"
#include "Performance.h"
#include "mozilla/dom/PerformanceMeasureBinding.h"
+#include "nsGkAtoms.h"
#include "nsRFPService.h"
using namespace mozilla::dom;
@@ -25,7 +26,8 @@ NS_IMPL_RELEASE_INHERITED(PerformancePaintTiming, PerformanceEntry)
PerformancePaintTiming::PerformancePaintTiming(Performance* aPerformance,
const nsAString& aName,
const TimeStamp& aStartTime)
- : PerformanceEntry(aPerformance->GetParentObject(), aName, u"paint"_ns),
+ : PerformanceEntry(aPerformance->GetParentObject(), aName,
+ nsGkAtoms::paint),
mPerformance(aPerformance),
mRawStartTime(aStartTime) {}
diff --git a/dom/performance/PerformanceResourceTiming.cpp b/dom/performance/PerformanceResourceTiming.cpp
@@ -8,6 +8,7 @@
#include "mozilla/dom/PerformanceResourceTimingBinding.h"
#include "nsArrayUtils.h"
+#include "nsGkAtoms.h"
#include "nsNetUtil.h"
using namespace mozilla::dom;
@@ -28,7 +29,8 @@ NS_IMPL_RELEASE_INHERITED(PerformanceResourceTiming, PerformanceEntry)
PerformanceResourceTiming::PerformanceResourceTiming(
UniquePtr<PerformanceTimingData>&& aPerformanceTiming,
Performance* aPerformance, const nsAString& aName)
- : PerformanceEntry(aPerformance->GetParentObject(), aName, u"resource"_ns),
+ : PerformanceEntry(aPerformance->GetParentObject(), aName,
+ nsGkAtoms::resource),
mTimingData(std::move(aPerformanceTiming)),
mPerformance(aPerformance) {
MOZ_RELEASE_ASSERT(mTimingData);
diff --git a/xpcom/ds/StaticAtoms.py b/xpcom/ds/StaticAtoms.py
@@ -608,6 +608,7 @@ STATIC_ATOMS = [
Atom("label", "label"),
Atom("lang", "lang"),
Atom("language", "language"),
+ Atom("largestContentfulPaint", "largest-contentful-paint"),
Atom("last", "last"),
Atom("layer", "layer"),
Atom("LayerActivity", "LayerActivity"),