Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92426 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63360 invoked from network); 18 Apr 2016 19:10:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Apr 2016 19:10:47 -0000 Authentication-Results: pb1.pair.com header.from=francois@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=francois@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 212.27.42.2 as permitted sender) X-PHP-List-Original-Sender: francois@php.net X-Host-Fingerprint: 212.27.42.2 smtp2-g21.free.fr Received: from [212.27.42.2] ([212.27.42.2:38809] helo=smtp2-g21.free.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D6/6D-11975-53135175 for ; Mon, 18 Apr 2016 15:10:46 -0400 Received: from [127.0.0.1] (unknown [82.240.16.115]) (Authenticated sender: flaupretre@free.fr) by smtp2-g21.free.fr (Postfix) with ESMTPSA id 94E6E2000FF; Mon, 18 Apr 2016 18:59:38 +0200 (CEST) To: Lin Yo-An , "internals@lists.php.net" References: Message-ID: <5715312D.4050904@php.net> Date: Mon, 18 Apr 2016 21:10:37 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Antivirus: avast! (VPS 160418-0, 18/04/2016), Outbound message X-Antivirus-Status: Clean Subject: Re: [PHP-DEV] Proposal: Startup snapshot for optimizing app load time From: francois@php.net (=?UTF-8?Q?Fran=c3=a7ois_Laupretre?=) 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: > > 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) > 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çois