Can V8 save the result of compiling JS functions/files to a file?

151 views
Skip to first unread message

Jiang Kelvin

unread,
Jan 26, 2015, 9:33:36 PM1/26/15
to v8-u...@googlegroups.com
Not all js files are online, such as the js files in extensions/web-apps/application-cache. If we can save the result of compilation when installing or upgrading them, and just load and run the binary codes when calling a js function(think about the ART of Android), is it possible to improve performance?

Jakob Kummerow

unread,
Jan 27, 2015, 4:55:14 AM1/27/15
to v8-u...@googlegroups.com
It's complicated.

V8 has a so-called "snapshotting" mechanism which is used to speed up startup. Recently people have been working on using it to cache other code as well.

That said, this is no silver bullet, as there are a number of inherent challenges:
- dynamic languages like JavaScript are not well-suited for ahead-of-time compilation
- generating optimized code depends on having collected type feedback, so it can't happen up front; it also by definition bakes in a number of non-cacheable assumptions
- generating non-optimized code, on the other hand, is relatively fast anyway (unless there's a huge amount of it), so caching it only helps so much
- assuming you have a working caching mechanism, you need reasonable rules when to use it, how much disk space you're giving it, how you're making sure it isn't stale, and so on.
- caching generated code doesn't affect sustained performance (possibly on the contrary), it can only improve startup time.

So having an explicit and time-consuming "installation"/pre-compilation phase for JS packages isn't going to happen. However, more automatic caching under the hood is something you're likely to see in the future (regardless of where scripts came from -- there's no reason this couldn't work with regular scripts found on web sites.)


On Tue, Jan 27, 2015 at 3:33 AM, Jiang Kelvin <leiy...@gmail.com> wrote:
Not all js files are online, such as the js files in extensions/web-apps/application-cache. If we can save the result of compilation when installing or upgrading them, and just load and run the binary codes when calling a js function(think about the ART of Android), is it possible to improve performance?

--
--
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.

Jiang Kelvin

unread,
Jan 28, 2015, 12:01:22 AM1/28/15
to v8-u...@googlegroups.com
Thanks for sharing the details of technology. Maybe it is also really hard to return a kind of serializable compiled code and let the embedder to handle(e.g. store) it.
I just thought about that if the "installation" process can do more. (For example if windows wanna run their applications on lots of devices based on X86/ARM/MIPS, I think a reasonable way is that do the back-end compiling works and linkings when installing.)

You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/2Gjwvzhjs0Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.

dunjun liu

unread,
Jan 29, 2015, 12:12:17 AM1/29/15
to v8-u...@googlegroups.com
so, if it that is possible to geneate non-optimized at other remote device then push and run on new running  devices, i means full compile JavaScript on cloud then excute genereted binary on  app installed devices.

在 2015年1月28日星期三 UTC+8下午1:01:22,Jiang Kelvin写道:

Yang Guo

unread,
Jan 30, 2015, 8:07:31 AM1/30/15
to v8-u...@googlegroups.com
You are welcome to play around with code caching. Take a look at CompileString in src/d8.cc or test/cctest/test-serialize.cc for examples.

xilu liu

unread,
Feb 1, 2015, 10:06:49 PM2/1/15
to v8-u...@googlegroups.com
Thanks, i will try what you said.

在 2015年1月30日星期五 UTC+8下午9:07:31,Yang Guo写道:

Louis Santillan

unread,
Feb 9, 2015, 12:13:00 PM2/9/15
to v8-u...@googlegroups.com
Does this mean that snapshotting for embedders has some support now?
And by support, I mean a bit of embedder documentation, and, a
documented API in v8.h. Because that could/would be interesting.

Jiang Kelvin

unread,
Mar 24, 2015, 9:31:06 PM3/24/15
to v8-u...@googlegroups.com
Code caching is another new technique that helps speed up page loading, specifically on repeated visits to the same page. Normally, the V8 engine compiles the page’s JavaScript on every visit, turning it into instructions that a processor understands. This compiled code is then discarded once a user navigates away from the page as compiled code is highly dependent on the state and context of the machine at compilation time. Chrome 42 introduces an advanced technique of storing a local copy of the compiled code, so that when the user returns to the page the downloading, parsing, and compiling steps can all be skipped. Across all page loads, this allows Chrome to avoid about 40% of compile time and saves precious battery on mobile devices.

Good news.
Reply all
Reply to author
Forward
0 new messages