Re: Proposal: Startup snapshot for optimizing app load time
| From: | François Laupretre | Date: | Mon, 18 Apr 2016 19:10:37 +0000 |
| Subject: | Re: Proposal: Startup snapshot for optimizing app load time | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92426@lists.php.net to get a copy of this message | ||
Hi,
Le 13/04/2016 17:55, Lin Yo-An a écrit :
Hi internals, The javascript engine V8 uses a strategy called "startup snapshot" to optimize app load time (see http://v8project.blogspot.tw/2015/09/custom-startup-snapshots.html for more details) The approach used by V8 creates a snapshot from heap, so the V8Context could be reused directly without re-running the bootstraping code. I think running javascript app in the browser is somehow like we run php script for each requests where the app bootstrapping code is required to be executed repeatedly for each request. Currently, our opcache extension can cache the byte codes, but the byte codes still need to be executed every time when bootstrapping an app, and which increases the overhead for each request. For example, a lot of applications use composer to initialize the class loader via the statement below:You are mixing 2 related mechanisms here : code persistence and data persistence. Code persistence (reloading the same code again and again in each request) is achieved through the autoloader. Autoloading, compbined with opcache provides a very fast mechanism to retrieve class definitions. If you measure the time taken by your 'require "vendor/autoload.php"' stance, you should find it to be extremely fast (with opcache on, of course). Data persistence is another question: the need here is to save and restore object instances. Several cache mechanisms exist for this, saving and restoring via serialize/unserialize. The problem with your 'bootstrap' approach (apart from the fact that it is not physically possible in PHP) is that you won't want to snapshot the *whole* environment, because you always want to keep at least some dynamic context. What you actually want to 'snapshot' is a set of well-defined object instances. So, the question, IMO, is to develop a mechanism faster than the current ones to store and retrieve object instances from memory. Regards Françoisrequire "vendor/autoload.php";The statement above produces thousands of byte code to run, which is to make an app ready. (If you use vld extension to show the opcodes)