Skip to content

added more information on gc and rooting#212

Draft
Narfinger wants to merge 8 commits intoservo:mainfrom
Narfinger:gc
Draft

added more information on gc and rooting#212
Narfinger wants to merge 8 commits intoservo:mainfrom
Narfinger:gc

Conversation

@Narfinger
Copy link
Contributor

This adds more information on Gc and rooting.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
```rust
#[dom_object]
struct Kittens {
children: Vec<Cat>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a stronger example if Cat was also a dom object, and you would use not Vec but Vec<Dom>, or even RefCell<Vec<Dom<Cat>>>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree making it a Vec<Dom>.
I don't know about RefCell though. There is a whole other section about borrow checking and RefCell which explains this very well.. I am going to link to that.

# Script

Servo is unique in that it uses garbage collection for some things that are non obvious. For example, every dom object
(a struct with `#[dom_object])` on it is controlled by spidermonkeys garbage collector. Extra care is to be taken when interacting with this. While the garbage collector is complicated and has multiple modes we will assume for now the following.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what extra care?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added that this is what the document is about.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
@Narfinger
Copy link
Contributor Author

Narfinger commented Mar 12, 2026

Thanks for the comments! Currently I can't look at the formatting and how it looks in compiled form that is why it is in draft mode (and so other people can check the correctness).
If somebody could contribute a small section how to use the rooted1 macro that would also be awesome.

Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In-progress review because I need to think more about this, and also sleep. We jump from a very simplistic view of the GC (it can happen anywhere! at any time!) to suddenly passing around a mutable pointer to the context and talking about unrooted values. I think we probably want to introduce the idea of &mut JSContext much earlier in this documentation, possibly in the first example.

Co-authored-by: Josh Matthews <josh@joshmatthews.net>
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
@Narfinger
Copy link
Contributor Author

Ok github screwed up a bit so I hope I got all the suggestions in.
I can think about a bit more how to include the JSContext stuff.

But I feel like it might not make sense to have it at the start. The start should be imho about why we need Gc anyway, What the rooted types are and how crown fits in all this.

Then (probably before performance subsection) we can introduce JSContext. Something like: "But Gc actually only runs when we do specific spidermonkey apis and having CanGC everywhere is hazardous".

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants