Bug 1804295, Add GeckoTasksBurst, r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D165133
This commit is contained in:
Olli Pettay 2022-12-27 13:12:22 +00:00
Родитель 2e25a827e0
Коммит 1130769354
3 изменённых файлов: 12 добавлений и 30 удалений

Просмотреть файл

@ -26,10 +26,8 @@ nsBaseAppShell::nsBaseAppShell()
: mSuspendNativeCount(0),
mEventloopNestingLevel(0),
mBlockedWait(nullptr),
mFavorPerf(0),
mNativeEventPending(false),
mStarvationDelay(0),
mSwitchTime(0),
mGeckoTaskBurstStartTime(0),
mLastNativeEventTime(0),
mEventloopNestingState(eEventloopNone),
mRunning(false),
@ -165,14 +163,9 @@ nsBaseAppShell::Exit(void) {
}
NS_IMETHODIMP
nsBaseAppShell::FavorPerformanceHint(bool favorPerfOverStarvation,
uint32_t starvationDelay) {
mStarvationDelay = PR_MillisecondsToInterval(starvationDelay);
if (favorPerfOverStarvation) {
++mFavorPerf;
} else {
--mFavorPerf;
mSwitchTime = PR_IntervalNow();
nsBaseAppShell::GeckoTaskBurst() {
if (mGeckoTaskBurstStartTime == 0) {
mGeckoTaskBurstStartTime = PR_IntervalNow();
}
return NS_OK;
}
@ -246,7 +239,9 @@ nsBaseAppShell::OnProcessNextEvent(nsIThreadInternal* thr, bool mayWait) {
// NativeEventCallback to process gecko events.
mProcessedGeckoEvents = false;
if (mFavorPerf <= 0 && start > mSwitchTime + mStarvationDelay) {
// Content processes always priorize gecko events.
if (!XRE_IsContentProcess() && (start > (mGeckoTaskBurstStartTime + limit))) {
mGeckoTaskBurstStartTime = 0;
// Favor pending native events
PRIntervalTime now = start;
bool keepGoing;

Просмотреть файл

@ -97,10 +97,8 @@ class nsBaseAppShell : public nsIAppShell,
* have been consumed by the inner event loop(s).
*/
bool* mBlockedWait;
int32_t mFavorPerf;
mozilla::Atomic<bool> mNativeEventPending;
PRIntervalTime mStarvationDelay;
PRIntervalTime mSwitchTime;
PRIntervalTime mGeckoTaskBurstStartTime;
PRIntervalTime mLastNativeEventTime;
enum EventloopNestingState {
eEventloopNone, // top level thread execution

Просмотреть файл

@ -35,22 +35,11 @@ interface nsIAppShell : nsISupports
void exit();
/**
* Give hint to native event queue notification mechanism. If the native
* platform needs to tradeoff performance vs. native event starvation this
* hint tells the native dispatch code which to favor. The default is to
* prevent native event starvation.
*
* Calls to this function may be nested. When the number of calls that pass
* PR_TRUE is subtracted from the number of calls that pass PR_FALSE is
* greater than 0, performance is given precedence over preventing event
* starvation.
*
* The starvationDelay arg is only used when favorPerfOverStarvation is
* PR_FALSE. It is the amount of time in milliseconds to wait before the
* PR_FALSE actually takes effect.
* Ask the native event queue notification mechanism to favor Gecko tasks
* (instead of native tasks) for a short while. (Content processes always
* favor Gecko tasks.)
*/
void favorPerformanceHint(in boolean favorPerfOverStarvation,
in unsigned long starvationDelay);
void geckoTaskBurst();
/**
* Suspends the use of additional platform-specific methods (besides the