[webkit-dev] Making more use of ScriptWrappable

Kentaro Hara haraken at google.com
Thu Nov 1 11:09:46 PDT 2012


Sounds like a good idea.

> For some objects, we store the wrapper
> inline in the object itself by making object inherit from
> ScriptWrappable.  For other types of objects, we use a HashMap to
> translate the object into a JavaScript wrapper.

The current situation is not "either ScriptWrappable or the HashMap".
Currently we store all wrappers into the HashMap and store some
wrappers into ScriptWrappable as a cache. In other words, wrappers
stored in ScrpitWrappable are also stored in the HashMap. The fact
that the HashMap knows all wrappers is being used at some places e.g.
when GC enumerate wrappers.

Thanks to the recent efforts of Adam Barth, V8 bindings are going to
remove the need to enumerate all wrappers, and thus the HashMap does
not need to store all wrappers. On the other hand, what about JSC
bindings?

Either way, I would support the idea of introducing ScriptWrappable
for more DOM objects.


On Thu, Nov 1, 2012 at 6:36 PM, Adam Barth <abarth at webkit.org> wrote:
> We currently use two different approaches for associating JavaScript
> wrappers with DOM objects.  For some objects, we store the wrapper
> inline in the object itself by making object inherit from
> ScriptWrappable.  For other types of objects, we use a HashMap to
> translate the object into a JavaScript wrapper.
>
> Whether to use ScriptWrappable or a HashMap is a trade-off that
> depends on the workload.  For DOM objects that rarely have a
> JavaScript wrapper, using a HashMap is more memory efficient because
> we don't need to store a large number of null pointers in objects that
> do not have wrappers.  By contrast, if an object almost always has a
> JavaScript wrapper, using ScriptWrappable is both faster (because we
> avoid the hash table lookup) and uses less memory (because we don't
> need to store both the key and the value in the HashMap---we just need
> to store the value in the object itself).
>
> Today, we use ScriptWrappable for Nodes only, but we would benefit by
> making more use of ScriptWrappable, particularly for DOM objects that
> almost always have JavaScript wrappers.  For example, XMLHttpRequest
> objects exist only when created by script, which means that every
> XMLHttpRequest object has a JavaScript wrapper.
>
> My plan is to introduce an interface-level IDL attribute named
> something like [OftenHasJSWrapper] that informs the code generator
> that the object inherits from ScriptWrappable and that we should make
> use of the inline wrapper.  We can then deploy this attribute as
> appropriate throughout WebCore to reduce memory usage and improve
> performance.
>
> Please let me know if you have any feedback.
>
> Thanks!
> Adam
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-dev



-- 
Kentaro Hara, Tokyo, Japan


More information about the webkit-dev mailing list