Per-isolate FunctionTemplate cache

25 views
Skip to first unread message

tbl...@icloud.com

unread,
Nov 20, 2016, 5:09:38 PM11/20/16
to v8-users
Jochen Eisinger said that "v8 has an per-isolate cache of function templates". I have a few questions about this cache:

If I create multiple FunctionTemplates with different callback data but the same callback function and everything else, does it only create one function template and use the cache for the rest?
If not, why does the cache exist?

~Theodore

Ben Noordhuis

unread,
Nov 21, 2016, 6:05:36 AM11/21/16
to v8-users
It creates multiple function templates. The cache is to speed up
template instantiation, not template creation.

Toon Verwaest

unread,
Nov 21, 2016, 7:01:31 AM11/21/16
to v8-users
I don't know which cache you are talking about. Afaik there's only a "function-template-instantations-cache". That caches JSFunctions per native context resulting from instantiating a function template.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tbl...@icloud.com

unread,
Nov 21, 2016, 1:12:22 PM11/21/16
to v8-users
Here's what Jochen originally said:

v8 has an per-isolate cache of function templates. As the string is referenced by the function template, it will never go out of scope.
I'd recommend to create a weak handle to the function you create via GetFunction() instead


He later clarified "the function template won't ever get gc'd after you've instantiated it once."

What I really want to know is why this is the case, and what purpose it serves.

~Theodore

Toon Verwaest

unread,
Nov 22, 2016, 11:05:29 AM11/22/16
to v8-users
If you do FunctionTemplate::New you get a caching template. With caching I mean: every time you instantiate the template in the same native context, you'll get the same function out. This is just how it's supposed to work for Blink. This cache keeps the function strongly since even if objects holding functions may disappear temporarily, the identity of the functions needs to be preserved.

For your case it seems like you could just do Function::New, which internally generates a non-caching template. That way there won't be a strong reference from the cache.

I hope this helps,
Toon

--
Reply all
Reply to author
Forward
0 new messages