Hi Christian, thanks for a prompt response. When I compile a script via v8::Script::Compile, it is "bound" to the current context in a certain way (for instance, references to objects in current context), so it is not possible to execute a compiled script in other context. Do I understand correctly that snapshot compilation works differently - in a sense that a compiled snapshot can be then executed in arbitrary context with same results?
Also, when exactly are compiled snapshots executed? For example, I do (now) this: 1) create empty context, 2) set global property "Config" as an empty object, 3) execute config.js (contains: "Config.someProperty = someValue"). In this scenario, I want config.js to be pre-compiled snapshot, but it shall not be executed prior to global.Config creation (#2). How can I achieve this? Sincerely, Ondrej Zara 2009/5/19 Christian Plesner Hansen <[email protected]> > > V8's snapshot feature exists exactly to address this issue. If you > build v8 with snapshot=on the native .js files will be compiled just > once, at vm compile time. That should make #4 disappear completely > even from the first run. > > > -- Christian > > On Tue, May 19, 2009 at 9:56 AM, ondras <[email protected]> wrote: > > > > Hi, > > > > I spent some time analyzing performance bottlenecks in v8cgi. A > > typical program flow in FastCGI/Apachemodule scenario is the > > following: > > > > 1) program & V8 initialization, > > 2) new request arrives, > > 3) new context is created, > > 4) default libraries (*.js files) are compiled and executed, > > 5) requested file (.js) is compiled and executed, > > 6) wait for new request, GOTO #2, > > 7) shutdown. > > > > According to valgrind, most problematic operation is #4. Every (http) > > request means compiling and executing of several javascript variables. > > In theory, there are two possible approaches to speed this up: > > > > A) Compile these files only once, execute them on each request; > > B) Do not create new context each time; save the initialized context > > and re-use it (this removes points #3 and #4 from all but first > > request). > > > > However, I am unable to successfully implement any of these points, > > because: > > > > A) It is _not_ possible to compile a script in context C1 and run it > > in other context C2 in V8. No errors are raised, but the compilation > > closely binds script to C1 and results in C2 are totally > > unpredictable. > > > > B) I don't know how to "freeze" or "clean" the context for re-using; > > user code (#5) can for instance do "Array.prototype.XXX = 3;" and I am > > not sure how to detect/revert this. > > > > > > Please, can you share your thoughts about how to solve these issues? > > Has anyone encountered the need to speed up script (re)compilation and/ > > or context reusing? > > > > > > > > Sincerely, > > Ondrej Zara > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ v8-users mailing list [email protected] http://groups.google.com/group/v8-users -~----------~----~----~----~------~----~------~--~---
