It should be possible to do this for functions and simple classes. Most probably this will require some engine changes, but this is not a big problem for major release. Conditional definition and run-time class inheritance will make significant troubles.
Thanks. Dmitry. ________________________________________ From: Lin Yo-An <cornelius.h...@gmail.com> Sent: Wednesday, April 13, 2016 18:55 To: internals@lists.php.net Subject: [PHP-DEV] Proposal: Startup snapshot for optimizing app load time 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: require "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) However, if we can support a simple syntax to describe what is doing "bootstrap", we are able to create a startup snapshot from it. The proposal here want to introduce some new syntax to optimize app load time though the below syntax: bootstrap "vendor/autoload.php"; // caches the context after running this script. Or bootstrap { require "vendor/autoload.php"; // do something else for making app ready }; And of course, we might detect the bootstrap script automatically without creating new syntax and opcodes, but I think it's hard to do because PHP applications can be written by many ways... Questions ======== I don't know if this approach is doable or not. Or maybe we can support this in a separated extension instead of changing the zend core? Do you guys think it's doable? would you like to share your idea for this? Best Regards, Yo-An Lin -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php