Hi,

Servo is new and opens new opportunities, so I'm going to share an idea. And maybe someone else had it already (I haven't read such a thing yet) or maybe it's too crazy of an idea, but the discussion may be interesting anyway.

HTML has <iframe>s. JavaScript can interact with it. There are 2 types of iframes with 2 different types of interactions: 1) same origin iframes. JS from the parent can mes around with the kid iframe 2) different-origin iframe. JS from the parent can only interact with it through message passing via postMessage. It's also possible via CSS and HTML attributes in the parent to change the size of the iframe content in the parent page (which is the viewport size for the iframe, right?) and probably another handful of such style changes which affect how the iframe is rendered.

It seems like in theory, it could be possible to handle the content of a cross-origin iframe in a specific Rust task (or bunch of tasks). The few allowed communications (postMessage, iframe size in the parent, etc.) would "just" be handled by cross-task communication.

Potential benefits:
* cross-origin iframes are loaded and run in parallel (a bit like WebWorkers with a UI if you will. So looking forward to transferables with cross-origin iframes!) * origin isolation (I feel Rust is already well-equipped for that, but it doesn't hurt) * when the iframe@src changes, all the memory that's specific to the task can be released directly without waiting for GC graph traversals or refcounting

I've written a small script to be used with scratchpad and the webconsole [1] and in a 30 minutes look, I've observed some pages with up to 11 cross-origin iframes in the same page, so it feels like it's worth a try. The idea of considering a cross-origin iframe as a WebWorker with a UI also has some appeal to be honest.


# Addendum: the special same origin iframe@sandbox case

What I've described above only applies to cross-origin iframes. As it happens, HTML5 introduced a sandbox attribute for iframes [2]. When applied, the iframe is suddenly put in its own unique origin (regardless of the origin inferred from its URL). So it could be possible to consider sandboxed same-origin iframes as parallelizable. Of course, in JavaScript, the parent of an iframe can, at any time, remove the sandbox attribute or add the "allow-same-origin" to the sandbox attribute (IIUC, this value gives back its origin to the content of an iframe). I don't know Rust enough to figure out if sandboxed same-origin iframes can't be parallelized at all or if it's just a very interesting engineering challenge (bring back to the parent content task the content of the iframe like if it was never in a different task whenever JS in the parent decides to ruin the optimization).

Thoughts?

David

[1] https://gist.github.com/DavidBruant/5032258
[2] https://developer.mozilla.org/en-US/docs/HTML/Element/iframe#Attributes
_______________________________________________
dev-servo mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-servo

Reply via email to