mirror of
https://github.com/servo/servo
synced 2026-04-25 17:15:48 +02:00
Page:
Mozlando Servo MagicDOM
Pages
Adding a new WebIDL binding
Alternative Logo Proposals and Related Swag
Asynchronous WebAssembly compilation project
Austin Oxidation
Autogeneration of style structs
Basic SVG support project
Beginner's guide to rebasing and squashing
Benchmarking
Benchmarks
Bots
Browser Engine Research
Build Errors FAQ
Buildbot administration
Building for Android
Building for Magic Leap
Building for UWP
Building on ARM desktop Linux
Building
CI Services we use
CSS parse error reporting
CSSOM student project
Canvas rendering project
Cargo upgrade service project
Code rust concurrency
Code Review
Code of Conduct
Coding standards
Compiler upgrade recipes
Compositor Layer Design
Contributing
Control Servo using WebDriver
Creating and viewing WARC web archives in Servo
Creating new OpenSSL Windows binary distributions
Cross compiling from linux to mac
Crowbot
Css selector matching meeting 2013 07 19
DOM Design
DOM documentation
DOM missing pieces
Debugging JS web compat issues
Debugging and editing tools
Debugging
Design
Developer tools student project
Devtools CSS errors
Devtools plans
Devtools
Diagnosing SpiderMonkey JIT issues
Eric Atkinson visit 2013 09 10
Events and sundry
Expand HTTP request response monitoring
Fetch improvement project
Firefox Reality release notes
FirefoxReality build
Firewall setup for servo master1
Focus student project
Form validation student project
GSoC project brainstorming
Garbage collected DOM
Getting started with layout
GitHub Labels
Github & Critic PR handling 101
Github workflow
Glossary
Governance
Graphics toolkit integration
HTML parser improvement project
HTMLElement binding conversion
HTTP archive support project
HTTP library requirements
Hawaii Rooting
High priority content for layout
Highfive
HoloLens 2 test plan
Home
How to generate GStreamer binaries for CI
Image load conformance student project
Image maps project
Implement HTML charset parsing project
Implement ImageBitmap project
Implement missing WebAudio automation student project
Implement support for missing XMLHttpRequest APIs
Implement worker modules
Implementing a web standard (RGSoC)
Improve specification conformance of unicode bidi library
Incremental flow tree construction
Infrastructure
Integrate xml5ever
Intern project brainstorming
Intern projects
JS objects, wrappers, and cross origin concerns 2013 08 07
Layout 2020
Layout Overview
Layout resources
Layout revamp ideas
Leo meyerovich visit 2013 07 22
Linux sandboxing
London Oxidation
London Security
Meeting 2014 10 27
Meeting 2014 12 08
Meeting 2012 02 08
Meeting 2012 02 16
Meeting 2012 07 20
Meeting 2013 04 01
Meeting 2013 04 15
Meeting 2013 04 22
Meeting 2013 04 29
Meeting 2013 05 06
Meeting 2013 05 13
Meeting 2013 05 20
Meeting 2013 06 03
Meeting 2013 06 10
Meeting 2013 06 14
Meeting 2013 06 17
Meeting 2013 06 24
Meeting 2013 07 01
Meeting 2013 07 15
Meeting 2013 07 22
Meeting 2013 07 29
Meeting 2013 08 05
Meeting 2013 08 12
Meeting 2013 08 19
Meeting 2013 09 09
Meeting 2013 09 16
Meeting 2013 09 23
Meeting 2013 09 30
Meeting 2013 10 14
Meeting 2013 10 21
Meeting 2013 10 28
Meeting 2013 11 04
Meeting 2013 11 18
Meeting 2013 11 25
Meeting 2013 12 02
Meeting 2013 12 09
Meeting 2013 12 16
Meeting 2014 01 06
Meeting 2014 01 13
Meeting 2014 01 21
Meeting 2014 01 27
Meeting 2014 02 03
Meeting 2014 02 10
Meeting 2014 02 24
Meeting 2014 03 10
Meeting 2014 03 17
Meeting 2014 03 24
Meeting 2014 03 31
Meeting 2014 04 07
Meeting 2014 04 14
Meeting 2014 04 21
Meeting 2014 04 28
Meeting 2014 05 05
Meeting 2014 05 13
Meeting 2014 05 19
Meeting 2014 06 09
Meeting 2014 06 17
Meeting 2014 06 23
Meeting 2014 06 30
Meeting 2014 07 07
Meeting 2014 07 14
Meeting 2014 07 21
Meeting 2014 07 29
Meeting 2014 08 04
Meeting 2014 08 11
Meeting 2014 08 12
Meeting 2014 08 18
Meeting 2014 08 25
Meeting 2014 09 08
Meeting 2014 09 15
Meeting 2014 09 22
Meeting 2014 09 29
Meeting 2014 10 06
Meeting 2014 10 13
Meeting 2014 10 20
Meeting 2014 11 10
Meeting 2014 11 17
Meeting 2014 11 24
Meeting 2014 12 15
Meeting 2015 01 05
Meeting 2015 01 12
Meeting 2015 01 26
Meeting 2015 02 09
Meeting 2015 02 23
Meeting 2015 03 02
Meeting 2015 03 16
Meeting 2015 03 30
Meeting 2015 04 06
Meeting 2015 04 13
Meeting 2015 04 27
Meeting 2015 05 04
Meeting 2015 05 11
Meeting 2015 05 18
Meeting 2015 06 01
Meeting 2015 06 08
Meeting 2015 06 15
Meeting 2015 07 06
Meeting 2015 07 13
Meeting 2015 07 27
Meeting 2015 08 10
Meeting 2015 08 17
Meeting 2015 08 24
Meeting 2015 08 31
Meeting 2015 09 14
Meeting 2015 09 21
Meeting 2015 09 28
Meeting 2015 10 05
Meeting 2015 10 12
Meeting 2015 10 19
Meeting 2015 10 26
Meeting 2015 11 02
Meeting 2015 11 09
Meeting 2015 11 16
Meeting 2015 11 30
Meeting 2016 01 04
Meeting 2016 01 11
Meeting 2016 01 25
Meeting 2016 02 01
Meeting 2016 02 08
Meeting 2016 02 22
Meeting 2016 03 07
Meeting 2016 03 21
Meeting Devtools Servo 2
Meetings
Microdata project
Minutes Hackathon 2012 03 27
Missing DOM features project
More ServiceWorker support project
More developer tools student project
Mozlandia Automation
Mozlandia B2S
Mozlandia JS
Mozlandia Rust In Gecko
Mozlandia WPT
Mozlandia gfx
Mozlando Devtools Servo
Mozlando Oxidation
Mozlando SM Servo
Mozlando Servo Bluetooth
Mozlando Servo MagicDOM
Mozlando Servo SMStrings
Mutation observer project
Mutation testing project
NCSU student projects
Network security project
Off main thread HTML parsing project
Offscreen canvas improvements project
Offscreen canvas project
Orlando Oxidation 2018
Oxidation 2015 11 05
Persistent sessions student project
Preparing ARM libraries for CI
Priority of CSS properties
Priority of DOM implementation
Priority of dom bindings
Private browsing student project
Profiling
Project proposal deadlines
Prototype JS form controls student project
Prototype ways of splitting the script crate
Publishing a new ANGLE NuGet version
Publishing a new app store release
Push vs Pull for caching
Random web content project
Refactor GLES2 student project
Refactor bluetooth support student project
Remaining work
Removing push notifications from IRC hooks
Replace C libraries student project
Report new contributors project
Representation of computed style
Research
Reviewer
Roadmap
Running Web Platform Tests on Servo
Rust HTML parser
Rust SpiderMonkey debugger API
Rust cssparser code walk 2013 08 02
SaltStack Administration
San Francisco Oxidation
Servo Benchmarking Report (December 2024)
Servo Benchmarking Report (November 2024)
Servo Benchmarking Report (October 2024)
Servo Layout Engines Report
Servo and SpiderMonkey Report
Servo for Gecko Developers
Specification Links
SpiderMonkey related tasks
SpiderMonkey infodump
SpiderMonkey upgrade details
Storage student project
Streaming webassembly student project
Strings
Student project brainstorm
Student projects
Styling overview
Stylo hacking guide
Summer of Code 2014: Implement XMLHttpRequest
Summer of Code 2016: Fetch API
Summer of Code 2016: File support
Summer of Code 2016: ServiceWorker infrastructure
Summer of Code projects
Summit meeting 2013 09 09
Support WebDriver based tests project
Syncing web platform tests (WPT)
TaskCluster
Testing
Tools
Tracking intermittent failures over time project
Transcription Notes from Servo Architecture talk in Suwon
Transcription notes from rust patterns talk in suwon
Transcription parallelism
Transcription rust concurrency
Transcription rust runtime
Transription layout and acid2
Trinity College Dublin student projects
UPenn student projects
Updating the Rust compiler used by Servo
Upgrading non taskcluster linux CI machines
Upgrading the UWP gstreamer binaries
Upgrading the windows LLVM binaries
Upgrading wptrunner
Using DOM types
Using Rust Spidermonkey Prototype
Using WebWorker Prototype
Version 0.1
Videos and presentations
WebAudio JS interfaces student project
WebAudio nodes student project
WebCompatBug
WebSocket student project
Webdriver student project
Webdriver tests student project
Webrender Overview
Whistler 2019 notes
Whistler Bugzilla
Whistler FFOS
Whistler GFX
Whistler Houdini1
Whistler Houdini2
Whistler Necko
Whistler Oxidation 2019
Work items for new contributors
Workweek COW DOM
Workweek alt js
Workweek android arm
Workweek boot 2 servo
Workweek compiler lints
Workweek displaylist
Workweek dogfooding
Workweek encoding
Workweek generated content
Workweek governance
Workweek graphics stack
Workweek graphics toolkit
Workweek incremental layout
Workweek js bindings status
Workweek layers
Workweek layers2
Workweek pixels
Workweek rasterization
Workweek reftests
Workweek roadmap
Workweek script crate
Workweek security
Workweek string interning
Workweek tables
Workweek writing modes
XML parser student project
infra triage notes
jQuery status
webxr.today support
Clone
3
Mozlando Servo MagicDOM
Lars Bergstrom edited this page 2015-12-12 09:50:26 -05:00
Table of Contents
- Overview
- Outline of the basic idea
- Memory consumption
- Self-hosted code
- jdm: Any heuristics for determining when self-hosted is better than native?
- jdm: Is magic DOM all-or-nothing? That is, for things mainly accessed in layout don't live in slots; others do?
- till: What are the GC implications?
- bz: You have something set up for rooting/tracing now, right?
- larsberg: Have we answered questions about whether we actually want to do magic DOM or not?
- bz: style system, when are tags interned and where?
- larsberg: So, how do we feel ?
- bz: Is it possible to set this up to compile either to magic DOM or today-code?
- Next steps
Overview
Outline of the basic idea
- Basic idea is to take advantage of reserved slots in JS objects.
- Is 16 slots enough for your purposes?
- It might not be.
- We can change it; just curious.
- We can create a special zero-sized object in Rust that is zero-sized, just accesses the fixed slots
- Contains a lot of type information abuot the slot contents, statically checked.
- don't need to tell the JS engine about what's in the slots
- Can get rid of finalizers, store all information on the object.
- Contains a lot of type information abuot the slot contents, statically checked.
- Interesting part is when we combine this with self-hosted JS code
- In the JS engine there si code for various JS interfaces implemented entirely in JS
- huge perf benefit for SpiderMonkey because of JIT optimization without special cases for native code
- Some complicated rules for writing this code, but they could be enforced by a transpiler.
- for example, can't just write a normal JS function; need to follow WebIDL rules about arg conversions
- but since it's all in JS, the JIT can do things like lift these conversions out of loops, or eliminate them
- Still have codegen, but it will be generating JS
- Generated code can be friendly to type analysis because args will always be a particular type of object
- I am creating a statically typed language that compiles to JS
- can write self-hosted JS implementations safely
- uses the Rust parser, looks like Rust syntax, simplified version of the language
- Doesn't use the Rust type checker, only the parser
- Could be converted into a Rust compiler plugin, so code can be inline in Servo DOM code.
- jack: If we write DOM code in JS we can potentially share with Gecko for "free", but not with Magic DOM?
- bz: Gecko would need to change its object layout, and also the Rust compiler plugin wouldn't work for Gecko
- bz: How do you plan to handle cross-compartment wrappers?
- are compartments only cross-process?
- same-origin iframes are in the same process/runtime but separate compartments, unless sandboxed
- mwu: I came across this problem with iframes. We might have specialized types to represent things that are wrapped.
- If you try to assign something to a slot that belongs to another compartment, the JS engine gets angry
- Better than what we have now using raw pointers that don't really assert anything.
- Needs investigation
- Related problem with proxies
- bz: We will fix it to make it possible to have reserved slots in proxies.
- mwu: Right now we re-wrap things
- bz: I suspect that handling CCW in self-hosted DOM code is going to be quite painful.
- are compartments only cross-process?
- bz: How do you handle CCW today? * jdm: We don't. And don't run with debug mozjs, so we don't get any assertions... * bz: You should start building with debug mozjs!
- jorendorf: Handling x-ray, security checks, etc. for CCW is going to be complicated
- bz: x-ray is used to handle DOM object / system code interactions
- Can't let the page interfere with the object by messing with standard prototypes, etc.
- till needs to solve some of this anyway, for Promises
- bz: the hard thing here is that you can't do your slot accesses from the x-ray compartment.
- mwu: As long as that get optimized out
- bz: Can make a slot intrinsic that knows how to operate on x-rays
- mwu: But everything is an x-ray?
- bz: No, x-ray is only for going from more-privileged to less-privileged code.
- In the JS engine there si code for various JS interfaces implemented entirely in JS
Memory consumption
- bz: Are you targeting 32-bit as well as 64-bit?
- Yes
- Besides pointers, can also play games with size of integer, boolean, etc.
- If you can make do with fewer slots, that's good.
Self-hosted code
- When doing self-hosted stuff, can you have a DOM interface that has some self-hosted methods and some native?
- I have an attribute to mark things self-hosted, can be per-method or whole-interface.
- When the JS runtime is created, self-hosted code is compiled into a separate compartment and then shared
- In all the actual content compartments you get lazy functions that are empty shells for the JS function
- on first invocation they get cloned over from the self-hosted compartment. Then they operate as normal JS functions.
- Normal JS functions except global name lookups aren't resolved on the normal global object.
- So if we're making an interface that requires queueing a task, that requires exposing an intrinsic?
- Yes. Just requires exposing a function to SpiderMonkey.
- For self-hosted APIs, do we have a Rust object defined for the DOM struct? A JS object with fields and stuff?
- mwu: Yes, that's all generated.
- jdm: In the transpiled language, you use field names to access the data in the slots?
- mwu: Yes.
jdm: Any heuristics for determining when self-hosted is better than native?
- mwu: If it doesn't have to interact in a difficult manner. Depends on how many other APIs we manage to implement in JS.
- Calls from JS to JS get a huge speedup.
- ajeffrey: Compile to both native rust and self-hosted from the same source code?
- mwu: They're fairly different things. It might work in some cases. But there's no &T in this language, can't express Rust semantics.
- No lifetimes, for example.
- nmatsakis: Could just use local variables instead. References would be possibly unsafe anyway. Should not support
&operator. Translatefoo.xto copying the pointer out... - mbrubeck: The generated Rust code from this Rust plugin code is going to look very different
- till: Yes, will not make sense to self-host everything
- mwu: Usually obvious from what the data structures are. If you can store it all in slots, implement as self-hosted JS.
- mwu: They're fairly different things. It might work in some cases. But there's no &T in this language, can't express Rust semantics.
- mwu: Often is obvious based on whether the data structures you need fit in the slots.
jdm: Is magic DOM all-or-nothing? That is, for things mainly accessed in layout don't live in slots; others do?
- mwu: Yes. I put things that don't make sense in a reserved slot into the heap as an extra slot. I have objects that are heap-only like that.
- jdm: Introducing an extra conversion from a private field every time. I would like to know how we can eliminate those where it's a bottleneck.
- mwu: Reference is immutable; I'm hoping that LLVM's alias analysis will figure out how to get the address of the heap-allocated object once and so avoid paying the penalties more than once.
- mwu: Everything does have to be magic DOM, but you can have ones that have a single slot that points at the reflector.
till: What are the GC implications?
- People are worried. Need finalization off main thread - so should be using background object types. Otherwise you visit every object in the heap in the foreground object twice.
- mwu: If we don't need finalization, we can kill the finalizer. Most DOM node objects can have it eliminated. There are a few, like some input fields.
- Might be able to teach classes about how to free specific offsets from the JS engine (via the host's allocator)
- nmatsakis: If the object is
Send, we may be able to run the finalizer from a background thread, sinceSendimplies that is safe - Working on taking marking off main thread, so only finalization would be on the main thread
- mwu: Also want to eliminate pointers w/in nodes. They store a tree structure; you should be able to store it elsewhere more efficiently. e.g., indexes w/ a table. Store it as a JS array, expose to JS...
- ajeffrey: If you have to compress it, don't you have to now write a GC in JS?
- bz: I just wouldn't gate your work on that, because there will be some compexities.
- mwu: I want to remove lots of the pointers inside of nodes.
- ajeffrey: Does this setup mean we don't have to trace Rust objects?
- mwu: Yes, in the vast majority of cases.
- ajeffrey: Is it 100%?
- bz: Could have event listeners, so you can't get out of it. Putting things into the array is hard.
- till: Could multi-heap help? Have things that are part of the DOM tree in their own heap.
- Sounds like you're not using zones, since everything in a different security context is already in a different thread and runtime. Could get rid of teh compartmental GCs, since you just want to clean everything. Don't know that it makes much sense to have a separate heap there. Something else is moving back to pinned values & allocating doubles on the heap again... would help with 32-bit size problems.
- bz: Should talk with Oleg about which things that the cycle collector collects well that now the GC will have to handle. THen, figure out how many of those are in real web pages, and you'll get a sense for how much more work you're putting on the GC. Certainly, the HTML spec with a half million DOM nodes is one such case. Possibly andrew (mccr8) too.
- If there are any GC problems, they're things that we need to fix for Gecko because they're related to our lists, too. Just bigger in Servo.
bz: You have something set up for rooting/tracing now, right?
- mwu: I think it works.
- bz: Hard case is creating an image, sets a load listener, and now the network fetch needs to keep the DOM node alive.
- jdm: We use persistent rooting for that.
larsberg: Have we answered questions about whether we actually want to do magic DOM or not?
- ms2ger: I'm worried about making heap allocations every time we touch a string, etc. from Rust... is touching strings from JS instead that much more important?
- mwu: We have to fix it anyway for reading strings.
- bz: How much of a problem is this string conversion problem? Or are you just running up against fundamental lower bounds?
- till: Much slower than gecko (in dromaeo) for things that touch strings.
- bz: Figure out what you're doing different from Gecko...
- ajeffrey: UCS2 vs. UTF8
- bz: You need to think long and hard about that.
bz: style system, when are tags interned and where?
- pcwalton: They're in the Rust string cache
- bz: Have a DOM object. Is that the same as the magic DOM object here? The one selector matching runs against?
- pcwalton: Yes. They are fields on an object.
- bz: What about new world?
- mwu: We have both a Rust atom string cache and the JS one...
- bz: If it's a JS string in the DOM object...
- mwu: It's not. All still native. Lots of optimization possible if we move to JS atoms instead of our own.
- pcwalton: Yes. Would hate to atomize during selector matching.
- till: Might be able to reduce copying by communicating the string representation between SM and Rust to avoid a conversion to export...
larsberg: So, how do we feel ?
- jdm: I like the transpiled language!
- ms2ger: I don't :-) So many new languages. JS, Rust, not-Rust/self-hosted...
- mwu: This will definitely give us the absolutely fastest bindings.
- ms2ger: It's also nice having compiled binaries. Now we have to delay startup times until JIT completes.
- till: Instead of JS source code could store the JS bytecode. Could certainly do for self-hosted SM code and should regardless of this conversation. After about 10 iterations, everything is super-fast.
bz: Is it possible to set this up to compile either to magic DOM or today-code?
- mwu: For struct side, yes. Provides some benefits to both today and tomorrow. Object layout can be switched. Not sure about the implementations.
- nmatsakis: I think it will work! We can look at the examples together.
Next steps
- Test this on a worst-case (tree traversal, lots of Rust code touching DOM objects, etc.).
- Contact Nikola for how to turn on alias analysis for references to reserved slots in DOM objects.