Closed Bug 1655683 Opened 4 years ago Closed 4 years ago

nsRFPService::ReduceTimePrecisionImpl is slow

Categories

(Core :: Security, defect, P2)

defect

Tracking

()

RESOLVED FIXED
Performance Impact high
Tracking Status
firefox87 --- fixed

People

(Reporter: smaug, Unassigned)

References

Details

(Keywords: perf:responsiveness)

Whiteboard: [qf:p3:responsiveness]

Dealing with timestamps should be very fast, but looks like ReduceTimePrecisionImpl ends up even doing allocations.

Blocks: 1655777
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → DUPLICATE
Whiteboard: [qf:p3:responsiveness] → [qf:p1:responsiveness]
No longer blocks: 1655777
Blocks: 1655777
Status: RESOLVED → REOPENED
Resolution: DUPLICATE → ---

https://share.firefox.dev/34EK2EC

https://farre.github.io/web-tools/rIC/index.html is a testcase.
Ensure "Show total allotted remaining time per update" and
"Use requestAnimationFrame" and
"Respect time remaining" are checked
and "Time to spend in idle callback" is 10
and click Toggle

Flags: needinfo?(ttung)
Flags: needinfo?(tom)

In that test it is expected that lots of time is spent in TimeRemaining, but looks like nsRFPService::ReduceTimePrecisionImpl is adding
quite a bit overhead there.
Is it RandomMidpoint calls which are slow? They are using a lock(!) in this super hot code path.

(In reply to Olli Pettay [:smaug] from comment #4)

In that test it is expected that lots of time is spent in TimeRemaining, but looks like nsRFPService::ReduceTimePrecisionImpl is adding
quite a bit overhead there.
Is it RandomMidpoint calls which are slow? They are using a lock(!) in this super hot code path.

I'm not very great at using the profiler but I would expect that - yes. https://bugzilla.mozilla.org/show_bug.cgi?id=1655777#c9 has some suggestions for narrowing down what part of the code the issue is in.

We could probably just remove the lock. We might hit race conditions: the impact of doing so would mean that individual timestamps might be jittered using the incorrect random values. But it would be very difficult for an attacker to control this, determine if it happened, or actually exploit this in a meaningful way. We could also look at the possibility of removing jitter entirely....

Flags: needinfo?(tom)

(In reply to Olli Pettay [:smaug] from comment #3)

https://share.firefox.dev/34EK2EC

https://farre.github.io/web-tools/rIC/index.html is a testcase.
Ensure "Show total allotted remaining time per update" and
"Use requestAnimationFrame" and
"Respect time remaining" are checked
and "Time to spend in idle callback" is 10
and click Toggle

I'm not so sure if I read the profiler correctly, but from this, I found there are some mozilla::detail::MutexImpl::lock above some nsRFPService::ReduceTimePrecisionImpl calls. And the only place which uses mutex lock in ReduceTimePrecision is RandomMidpoint.

Flags: needinfo?(ttung)
Severity: -- → S3
Priority: -- → P2
Blocks: 1686930

https://bugzilla.mozilla.org/show_bug.cgi?id=1686930 is another instance, there this shows up really badly.

Depends on: 1688326
Depends on: 1688330
Depends on: 1688694

is this resolved now?

Flags: needinfo?(bugs)

I profiled https://farre.github.io/web-tools/rIC/index.html again and it looked fine.

Status: REOPENED → RESOLVED
Closed: 4 years ago4 years ago
Resolution: --- → FIXED

(hmm, why the needinfo wasn't cleared in comment 9)

Flags: needinfo?(bugs)
Performance Impact: --- → P1
Whiteboard: [qf:p1:responsiveness]
You need to log in before you can comment on or make changes to this bug.