Bug 22308 - Improve Worker GC behavior
Summary: Improve Worker GC behavior
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Alexey Proskuryakov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-17 06:18 PST by Alexey Proskuryakov
Modified: 2008-11-18 00:45 PST (History)
0 users

See Also:


Attachments
proposed patch (13.77 KB, patch)
2008-11-17 06:27 PST, Alexey Proskuryakov
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Proskuryakov 2008-11-17 06:18:07 PST
Here is what Firefox beta does, and what I suggest that we do as well.

Worker object is GC protected if:
- there is JS executing in its thread,
- there are pending messages in any direction, or
- there is an active object in worker thread, such as a timer, async XHR etc.

A particular feature of this approach is that workers that have made a setInterval() call, or just run a tight loop, will not be collected until their owner is destroyed, even if there is no way left for them to communicate in either direction. This can be seen as a problem leading to likely resource leakage, or as a feature.

There will also be a terminate() call to manually shut down a worker, which Firefox doesn't currently provide.
Comment 1 Alexey Proskuryakov 2008-11-17 06:27:48 PST
Created attachment 25211 [details]
proposed patch
Comment 2 Darin Adler 2008-11-17 09:23:49 PST
Comment on attachment 25211 [details]
proposed patch

> +        Made hasPendingActivity() virtul, letting Worker add behavior to it.

Misspelled virtual here.

> +    m_workerContext->thread()->messagingProxy()->reportWorkerThreadActivity(false, m_workerContext->hasPendingActivity());

The use of booleans makes this a little hard to read. It's not obvious what that false means. We can use enums to construct named booleans which help make call sites like this easier to read.

r=me
Comment 3 Alexey Proskuryakov 2008-11-18 00:45:30 PST
Committed revision 38549.

(In reply to comment #2)
> > +    m_workerContext->thread()->messagingProxy()->reportWorkerThreadActivity(false, m_workerContext->hasPendingActivity());
> 
> The use of booleans makes this a little hard to read. It's not obvious what
> that false means. We can use enums to construct named booleans which help make
> call sites like this easier to read.

I've split this into two functions, reportWorkerThreadActivity and confirmWorkerThreadMessage.