Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92251 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9514 invoked from network); 13 Apr 2016 16:37:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Apr 2016 16:37:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.26 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.26 out2-smtp.messagingengine.com Received: from [66.111.4.26] ([66.111.4.26:36917] helo=out2-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F3/72-26321-1D57E075 for ; Wed, 13 Apr 2016 12:37:37 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 169BE207F8 for ; Wed, 13 Apr 2016 12:37:34 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Wed, 13 Apr 2016 12:37:34 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=w3b87DjWe3rrn0q GEXwOZm+4E8I=; b=WERMij9yHBOWdCRTDSzMr8FQlB1zor4U66nsVbsQV2xS0nR uqkUMNJOICdlg50SaZnDEK1I+VZchAKxa1jabQThBnk67FHjFOYtDZ2tLf+bncbA 34I/recNDHuzWmJP2nWHp9lNQEp/Y9FOGCJ5+MJLj0kKShjXgcxH4X4mMR0M= X-Sasl-enc: m1CEsl4NQHNOPidS+RFWtMHSqa3B3km1oTFOAUCZEO6z 1460565453 Received: from Crells-MacBook-Pro.local (unknown [63.250.249.138]) by mail.messagingengine.com (Postfix) with ESMTPA id CBDDA6800CE for ; Wed, 13 Apr 2016 12:37:33 -0400 (EDT) To: internals@lists.php.net References: Message-ID: <570E75CD.5070607@garfieldtech.com> Date: Wed, 13 Apr 2016 11:37:33 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Proposal: Startup snapshot for optimizing app load time From: larry@garfieldtech.com (Larry Garfield) On 4/13/16 10:55 AM, Lin Yo-An wrote: > 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? I have no idea how feasible it is for the engine. It may be impossible, or it may be straightforward. However, if it can be done then it would allow for vastly improved architecture for large applications. Many large systems (Drupal being the example I know best) spend a lot of time trying to optimize their bootstrap, loading as few services as possible, adding complexity and indirection to lazy-load services, etc. because that code is executed on every request. That means even a single function call removed along that critical path can add up to a lot of time over the course of a day. If instead we could snapshot a point in time and restart there, we could remove all of that optimization and make the bootstrap process actively load most of the system, then freeze it; then requests come in to a fully booted system and we save a ton of time initializing services on every request. I'd love that. The trick, of course, is that PHP's standard setup model assumes that the environment is created before the code is even loaded. The superglobals, for instance, exist before the first line of userspace code, yet those are the things that will vary per run *after* the snapshot is made. And then there's the question of how to detect and trigger a re-bootstrap, say when code is updated. For that reason, I suspect such a change would require far more than just a few new keywords; there would need to be some sever-level specification of a bootstrap script that is distinct from the user-facing script that the web server executes, and a few thousand edge cases to think about. -- --Larry Garfield