Closed Bug 928893 Opened 11 years ago Closed 3 years ago

Provide an API for processing DOM trees without blocking the main thread

Categories

(Core :: DOM: HTML Parser, defect, P5)

defect

Tracking

()

RESOLVED WONTFIX

People

(Reporter: Yoric, Unassigned)

Details

The standard API for DOMParser is blocking and consumes strings. That's two reasons that make it ill-suited for main thread use, but a very good candidate for workers. Admittedly, there are very good reasons to not expose it to workers, but it would be great if we could have a DOMParser subset for workers.

Main application scenario: read document off the main thread, apply some pre-treatment (e.g. localization, validation, script sanitization, etc.), then pass the data in some efficient manner (yet to be determined) to the main thread for actual display.
QA Contact: florian
It's a terrible candidate for workers. None of the Node classes can be used off the main thread, so there's nothing useful for it to do in workers.

However, there was a suggestion from abarth recently to create a variant of parseFromString that return a promise. That seems more feasible, if people want to implement that.
QA Contact: florian
(Note that I wrote *subset*, I'm aware that we won't have everything, far from it.)

While parseFromString with a promise would certainly be useful (provided the implementation is non-blocking), I would really want to apply any kind of pre-treatment to my document without blocking the main thread. This means doing it in a Web Worker, or something equivalent, perhaps a hidden sandboxed iframe – assuming that is non-blocking.
(In reply to David Rajchenbach Teller [:Yoric] from comment #2)
> (Note that I wrote *subset*, I'm aware that we won't have everything, far
> from it.)

Well, the output of DOMParser is a DOM tree and those can't live in Workers, so it's pretty hard to have a subset.

If a subset means a second DOM implementation for Workers, then the part about passing the data to the main thread in an *efficient manner* becomes a problem.

> or something equivalent, perhaps a hidden
> sandboxed iframe

That's totally different.

> assuming that is non-blocking.

Does e10s allow sandboxed iframes to be in a separate process?
(In reply to Henri Sivonen (:hsivonen) from comment #3)

> > or something equivalent, perhaps a hidden
> > sandboxed iframe
> 
> That's totally different.
> 
> > assuming that is non-blocking.
> 
> Does e10s allow sandboxed iframes to be in a separate process?

Setting the remote="true" attribute on an iframe will make e10s load it in a separate process. See http://hg.mozilla.org/mozilla-central/annotate/23c23b472a4f/toolkit/components/social/FrameWorker.jsm#l185 for an example in SocialAPI.
(In reply to Henri Sivonen (:hsivonen) from comment #3)
> (In reply to David Rajchenbach Teller [:Yoric] from comment #2)
> > (Note that I wrote *subset*, I'm aware that we won't have everything, far
> > from it.)
> 
> Well, the output of DOMParser is a DOM tree and those can't live in Workers,
> so it's pretty hard to have a subset.
> 
> If a subset means a second DOM implementation for Workers, then the part
> about passing the data to the main thread in an *efficient manner* becomes a
> problem.

Indeed. If the API is meant to be for pre-processing only, TypedObjects might possibly be useful.

> > or something equivalent, perhaps a hidden
> > sandboxed iframe
> 
> That's totally different.

You are right, this is totally different. Adapting the bug topic to I am concentrating on the feature ("I want to apply pre-processing to my DOM tree without causing reflows or otherwise blocking the UI"), rather than the implementation mechanism.

> 
> > assuming that is non-blocking.
> 
> Does e10s allow sandboxed iframes to be in a separate process?

I'll ask around.
Summary: DOMParser for workers → Provide an API for processing DOM trees without blocking the main thread
(In reply to Florian Quèze [:florian] [:flo] from comment #4)
> > Does e10s allow sandboxed iframes to be in a separate process?
> 
> Setting the remote="true" attribute on an iframe will make e10s load it in a
> separate process. See
> http://hg.mozilla.org/mozilla-central/annotate/23c23b472a4f/toolkit/
> components/social/FrameWorker.jsm#l185 for an example in SocialAPI.

Apparently, that's not fully implemented yet - bug 879475.
Whiteboard: [Async] → [Async:ready]
Whiteboard: [Async:ready]

Bulk-downgrade of unassigned, >=5 years untouched DOM/Storage bugs' priority and severity.

If you have reason to believe this is wrong, please write a comment and ni :jstutte.

Severity: normal → S4
Priority: -- → P5

Seem unlikely that we'd add a browser-provided DOM-like thing for Workers that would provide enough value compared to such things implemented in pure JS.

Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.