Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Introducing parent/children relationship in the ObjectActor

15 views
Skip to first unread message

Nicolas Chevobbe

unread,
Oct 13, 2017, 12:27:36 PM10/13/17
to dev-devel...@lists.mozilla.org
Hello devtoolers,

When we log a variable in the console panel, if it is not a primitive an
ObjectActor is created so we can use it as a reference for future
operations (fetching properties mainly, since we only send a "preview" in
the packet).
Then when we don't need the actor anymore (e.g. when the console is
cleared), we can release it so it does not consume unnecessary memory.
One of the feature of the ObjectActor is that for a given variable, we can
create multiple actors.
if we take the following code :

```
var a = { foo: { bar: 1 } };
console.log(a)
```

We'll end up with 2 actors, one for `a`, and another one for the inner `{
bar: 1 }` object .
Now because we send this in a single grip from the server to the client,
the consumer need to keep track of all those different actors, to release
them when they are not needed anymore.
Given the variety of grips shape, those actors references can be spread all
over the packet we receive (`ownProperties`, `ownSymbols`, `descriptor`,
`entries`, …) and it is something all the consumers (console, debugger,
objectInspector, extension …) need to handle.

We were thinking that it would be nice to have something in the ObjectActor
which would allow us to release all the actors in a grip by simply calling
release on the "root" ObjectActor (in the code example, it would be the `a`
actor only).

We do have a concern though, would there be some cases when releasing a
parent we *do not* want to release its children ? We don't have anything
that comes to mind, but you may have specific case that would need such
thing.

If you do, please shout so we take care of your case too. If everyone is
fine with that, we'll start working on this next week :)

Thanks !

Nick Fitzgerald

unread,
Oct 13, 2017, 2:51:11 PM10/13/17
to Nicolas Chevobbe, dev-developer-tools
Hi!

On Fri, Oct 13, 2017 at 9:27 AM, Nicolas Chevobbe <nche...@mozilla.com>
wrote:

> Hello devtoolers,
>
> When we log a variable in the console panel, if it is not a primitive an
> ObjectActor is created so we can use it as a reference for future
> operations (fetching properties mainly, since we only send a "preview" in
> the packet).
> Then when we don't need the actor anymore (e.g. when the console is
> cleared), we can release it so it does not consume unnecessary memory.
> One of the feature of the ObjectActor is that for a given variable, we can
> create multiple actors.
> if we take the following code :
>
> ```
> var a = { foo: { bar: 1 } };
> console.log(a)
> ```
>
> We'll end up with 2 actors, one for `a`, and another one for the inner `{
> bar: 1 }` object .
>

​I thought we used a weak map to ensure that each object only ends up with
a single actor? Is that not the case? Or not the case anymore?​ It was on
the object actor pool IIRC... perhaps that is only for the debugger's
object actors and not the console's?

With multiple actors for the same object, beyond a general grating against
aesthetics of perceived efficiency devoid of any measurements, there are
opportunities for the actors to get out of sync. As you allude to, keeping
one thing up to date is usually simpler than keeping many things up to date.



> We were thinking that it would be nice to have something in the ObjectActor
> which would allow us to release all the actors in a grip by simply calling
> release on the "root" ObjectActor (in the code example, it would be the `a`
> actor only).
>

​This sounds an awful lot like what the actor pools​ were created for. Have
you looked into using them in this situation?



>
> We do have a concern though, would there be some cases when releasing a
> parent we *do not* want to release its children ? We don't have anything
> that comes to mind, but you may have specific case that would need such
> thing.
>

​If there were such a scenario, it would be best to re-parent the children
to the about-to-be-released-parent's parent or actor pool.​ That way the
tree ownership discipline is preserved.

​Hope this is helpful, it's been a while since I touched this stuff :-p

Cheers!

Nick​
0 new messages