Bug 1843534 - Avoid measuring protect time when write-protection is disabled. r=jandem

On certain devices we have seen that taking frequent timestamps can be
expensive. Currently we measure the time taken to write protect JIT
code, and as this is a hot path we see these timestamps show up in
profiles. However, since bug 1835876 we no longer write protect code
in content processes. This patch therefore avoids measuring the time
when write protection is disabled.

Differential Revision: https://phabricator.services.mozilla.com/D185005
This commit is contained in:
Jamie Nicol 2023-08-09 10:28:36 +00:00
Родитель 5b33bdd436
Коммит 7a78be9a55
1 изменённых файлов: 9 добавлений и 3 удалений

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

@ -53,10 +53,16 @@ class MOZ_RAII AutoWritableJitCodeFallible {
}
~AutoWritableJitCodeFallible() {
mozilla::TimeStamp startTime = mozilla::TimeStamp::Now();
// Taking TimeStamps frequently can be expensive, and there's no point
// measuring this if write protection is disabled.
const bool measuringTime = JitOptions.writeProtectCode;
const mozilla::TimeStamp startTime =
measuringTime ? mozilla::TimeStamp::Now() : mozilla::TimeStamp();
auto timer = mozilla::MakeScopeExit([&] {
if (Realm* realm = rt_->mainContextFromOwnThread()->realm()) {
realm->timers.protectTime += mozilla::TimeStamp::Now() - startTime;
if (measuringTime) {
if (Realm* realm = rt_->mainContextFromOwnThread()->realm()) {
realm->timers.protectTime += mozilla::TimeStamp::Now() - startTime;
}
}
});