Investigate removing Add/RemoveRawValueRoot API

NEW
Unassigned

Status

()

Core
JavaScript: GC
P3
normal
a year ago
9 months ago

People

(Reporter: jonco, Unassigned)

Tracking

({triage-deferred})

55 Branch
triage-deferred
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

a year ago
This is only used in a couple of places (ErrorResult and in XPConnect).  It would be great if we could remove this API and use something else for these instead.
Keywords: triage-deferred
Priority: -- → P3
Sorry if I ask stupied question, so in this bug, should we try to replace ErrorResult.mJSException with PersistentRooted<Value>?
And for PersistentRooted, we don't have to unroot it, so we simply remove call to RemoveRawValueRoot?

Thanks
(In reply to Yoshi Huang [:allstars.chh] from comment #1)
> Sorry if I ask stupied question, so in this bug, should we try to replace
> ErrorResult.mJSException with PersistentRooted<Value>?
> And for PersistentRooted, we don't have to unroot it, so we simply remove
> call to RemoveRawValueRoot?

It isn't a stupid question. I'm not an expert on this code, but I suspect the reason it isn't just a PersistentRooted<> is to avoid the overhead of rooting in the (common?) case when mJSException is not set. I think this class is very performance sensitive. Maybe something like Maybe<PersistentRooted<Value>> would avoid the overhead. If that is allowed.
This API is also used in two places in the Servo code we have in the tree, but it looks like it is for DOM bindings for callbacks and promises, so I think it would only affect Servo, not Firefox.

The XPConnect code that uses this API doesn't look super performance sensitive. Somebody would have to figure out what this XPTCVariant thing is doing and why.
One of the design goals for ErrorResult was to be zero-cost, or as close as possible, when no exception is thrown (which is by far the common case).  The context was bindings code, where we were literally counting every CPU cycle.

That means a no-op (in opt builds) inlined destructor and a constructor that does the smallest amount of work possible (just inits mResult to NS_OK).

PersistentRooted fails the zero-cost design criterion badly, obviously.  Maybe<PersistentRooted> fails it too, by introducing extra branches and extra writes.

Now maybe we can live with those, especially on x86 where branch predictors work pretty well (unlike ARM).  We'd need to measure carefully.

Of course the tradeoff is that you _can_ leak via an ErrorResult if you're not careful and we have all sorts of assertions to catch code that might do that...  More RAII would let us have a bit more safety here.
You need to log in before you can comment on or make changes to this bug.