Closed Bug 1354616 Opened 7 years ago Closed 7 years ago

Removing timers (due to firing or cancellation) can be really slow)

Categories

(Core :: XPCOM, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
Performance Impact high
Tracking Status
firefox55 --- affected

People

(Reporter: bzbarsky, Assigned: bzbarsky)

References

Details

I just had my browser acting very slowly, mostly because I left about:performance running for too long, I think, and it got really slow.

I profiled it, and there was a bunch of timer stuff happening (GC, etc, etc), but the thing that jumped out at me is that in the chrom process we spent a _lot_ of time in TimerThread::RemoveTimerInternal.   And when I say a lot, I mean 25% of the chrome-process samples were in this function, for a total of 2.5s of runtime.

The problem, I assume, is that I had a ton of outstanding timers (e.g. because they were being throttled?) and RemoveTimerInternal ends up doing O(N) work, either in finding the right timer or in the resulting memmove.

The problem is that I'm not sure which it is, an the profiler won't tell me.  If it's finding the right timer, seems like we could RemoveElementSorted, right?  But if it's the memmove, then I'm not sure how best to deal, because switching to a linked list will make it hard to do binary sort insertion.

Looking at the profile, most of the removals are coming from nsTimerImpl::Cancel, and the rest from nsTimerImpl::InitCommon.  So I suspect it's the finding bit, especially for the latter: in that case the timer is kinda known to not be in the list!

Nathan, can you see a problem with using RemoveElementSorted in RemoveTimerInternal?
Flags: needinfo?(nfroyd)
(In reply to Boris Zbarsky [:bz] (still a bit busy) (if a patch has no decent message, automatic r-) from comment #0)
> Nathan, can you see a problem with using RemoveElementSorted in
> RemoveTimerInternal?

I don't--we only ever insert sorted, and we ought to be able to remove sorted, too.

FWIW, bkelly had a small patch series to optimize how we store things in bug 1325254.
Flags: needinfo?(nfroyd)
Ah, looks like the "Make nsITimer::Cancel() O(c)" patch there would effectively address this...
Depends on: 1325254
I'm going to assign this just for tracking purposes, but bz was going to look into polishing up the patches for bug 1325254.
Assignee: nobody → nfroyd
Status: NEW → ASSIGNED
There's nothing left to do here now that the dependent bug has landed, correct?
Flags: needinfo?(bzbarsky)
I believe that's correct, yes.
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Flags: needinfo?(bzbarsky)
Resolution: --- → FIXED
Assignee: nfroyd → bzbarsky
Performance Impact: --- → P1
Whiteboard: [qf:p1]
You need to log in before you can comment on or make changes to this bug.