Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83564 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41768 invoked from network); 23 Feb 2015 11:54:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Feb 2015 11:54:09 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.176 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.176 mail-vc0-f176.google.com Received: from [209.85.220.176] ([209.85.220.176:53080] helo=mail-vc0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 32/6D-01128-FD41BE45 for ; Mon, 23 Feb 2015 06:54:07 -0500 Received: by mail-vc0-f176.google.com with SMTP id la4so7140979vcb.7 for ; Mon, 23 Feb 2015 03:54:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=zM59xAqV8WAoBdOfuphFOP855gHVNlrlyqxWpfMwW1s=; b=jl1Q7vbjDt4sinPC/hGYMusirF4pzvLCa/1VgYfp0trfKye2vefo3/27llDVqq6blJ zm2h+Hu62NkT3by1HbhCfiYZNmVp4sxo9zZwu64Ndho5N+9lXSfYiZN3IiFhVv079FWS RH2PwKnVWe7lG0apG0xcExrVw6qlkkB+PBP0AhQ610tg4JpG9J7hOXoaaKP0FNzF0yKH cFsEy+EtK2N6nbxtT8gFzwYLsBqgz6NQM2qPEcew8Ovsod8RV+ZWIKY3XGpUvEAsakBT dTJPQ035gUfvBeUg4gpAVbaA+N3wfdhJPYegcAMMD8XLV+Yx69HeM0DU77kIsTyUGsji 4Ekw== X-Gm-Message-State: ALoCoQmYCGvrKjpRP3o/YOnQmNYoeguxpI+JNbatek3bWDMTOuAisnEVKqxAUVEZlB/QhZ5WbULGjTeEfEbC26ie48MmdL8/9R6ZFkEQYeR6zNf/54fWo2DHUEvE9Pegg5nR6OUmg3zl61KKYAqCqvyBfkMQedcsFA== MIME-Version: 1.0 X-Received: by 10.52.25.11 with SMTP id y11mr10113914vdf.51.1424692444451; Mon, 23 Feb 2015 03:54:04 -0800 (PST) Received: by 10.52.113.231 with HTTP; Mon, 23 Feb 2015 03:54:03 -0800 (PST) Received: by 10.52.113.231 with HTTP; Mon, 23 Feb 2015 03:54:03 -0800 (PST) In-Reply-To: References: <7ef509ef10bb345c792f9d259c7a3fbb@mail.gmail.com> <8250289916f5128b5bc1a114428d374e@mail.gmail.com> <54E9E6B5.3030905@gmail.com> Date: Mon, 23 Feb 2015 15:54:03 +0400 Message-ID: To: Joe Watkins Cc: Etienne Kneuss , Jefferson Gonzalez , PHP internals , Anthony Ferrara , Zeev Suraski Content-Type: multipart/alternative; boundary=001a1133e5f21140cf050fc00faa Subject: Re: [PHP-DEV] Coercive Scalar Type Hints RFC From: dmitry@zend.com (Dmitry Stogov) --001a1133e5f21140cf050fc00faa Content-Type: text/plain; charset=UTF-8 On Feb 22, 2015 6:07 PM, "Joe Watkins" wrote: > > > 1. Does weak mode could provide the required rules to implement a JIT > with a sane level of memory and CPU usage? > > There is no objective answer to the question while it has the clause "with > a sane level of ...". > > The assertion in the RFC that says there is no difference between strict > and weak types, in the context of a JIT/AOT compiler, is wrong. > > function add(int $l, int $r) { > return $l + $r; > } > > The first instruction in the interpreted code is not ZEND_ADD, first, > parameters must be received from the stack. PHP7 interpreter skips RECV instructions without type hints, because they do nothing. with type hints, they may perform checks and conversion. > > If that's a strict function, then un-stacking parameters is relatively > easy, if it's a dynamic function then you have to generate code that is > considerably more complicated. in both cases code is similar - an additional call on slow path if (UNEXPECTED(!valid_type(arg)) { // slow path zend_error(...) or convert_to_type(arg); } The problem with run-time switch is the fact that we will have to generate additional check and both calls in slow patch. This is why I'm against the run-time declare() switch. > > This is an inescapable difference, of the the kind that definitely does > have a negative impact on implementation complexity, runtime, and > maintainability. > > To me, it only makes sense to compile strict code AOT or JIT; If you want > dynamic behaviour, we have an extremely mature platform for that. Strictness is defined on call-site. So when you compile a function, you don't know with what semantic it's going to be called. Now think about different declare(strict) setting in different files and call chain. Do you see the mess? :) > > > 2. ... With that said, if a JIT implementation is developed will the > story of the ZendOptimizer being a commercial solution will be repeated or > would this JIT implementation would be part of the core? > > There should hopefully be no need to complicate the core with the > implementation, the number of people that are capable of maintaining Zend > is low enough already, the number of people able to maintain something as > new (for us) and complex as a JIT/AOT engine is even less, I fear. > > I think it's likely that Anthony and I, and Dmitry want different things > for a JIT/AOT engine. I think Anthony and I are preferring an engine that > requires minimal inference because type information is present (or > implicit), while Dmitry probably favours the kind that can infer at > runtime, the dynamic kind, like Zend is today. They are a world apart, I > think, I'll be happy to be proven wrong about that. I think our approches were very similar and leaded us to simular decisions, however we alredy tried jit-ing bench.php with type hints (strict). While JIT itselv makes bench.php about 5 times faster, type hints adds about 2%. Strict or weak make no difference at all. > > I like to think that even if Dmitry wrote it all by himself, it would be > opensource from the start, in fact I don't think that will happen. I'm > hoping we'll all work on the same solution together. We are going to open our work soon, but we are not going to work on it actevely, because all the forces at PHP7. Thanks. Dmitry. > > Cheers > Joe > > > > > On Sun, Feb 22, 2015 at 2:24 PM, Jefferson Gonzalez > wrote: > > > On 02/22/2015 09:00 AM, Etienne Kneuss wrote: > > > > There have been several attempts: > >> for JS: http://users-cs.au.dk/simonhj/tajs2009.pdf > >> or similar techniques applied to PHP, quite outdated though: > >> https://github.com/colder/phantm > >> > >> You are right that the lack of static information about types is (one of > >> the) a main issue. Recovering the types has typically a huge performance > >> cost, or is unreliable > >> > >> But seriously, time is getting wasted on this argument; it's actually a > >> no-brainer: more static information helps tools that rely on static > >> information. Yes. Absolutely. 100%. > >> > >> The question is rather: at what weight should we take (potential/future) > >> external tools into account when developping language features? > >> > >> > > Previous on the list nodejs JIT engine was mentioned as a working example > > of a JIT without the language having any sort of type information. While > > this is true I think it should also be considered the amount of checks and > > resources required for the generated machine code to achieve this. On this > > tests you can see that in most situations the javascript v8 engine used on > > nodejs uses much more memory than that of current PHP (compare it to C > > also) ( benchmarksgame.alioth.debian.org/u64/compare.php?lang=v8&lang2=php) > > Yes, it is faster, but it consumes much more CPU and RAM in most > > situations, and I'm sure that it is related to the dynamic nature of the > > language. > > > > A JIT or AOT machine code generator IMHO will never have a decent use of > > system resources without some sort of strong/strict typed rules, somebody > > explain if thats not the case. > > > > As I see it, some example, if the JIT generated C++ code to then generate > > the machine code: > > > > function calc(int $val1, int $val2) : int {return $val1 + $val2;} > > > > On weak mode I see the generated code would be something like this: > > > > Variant* calc(Variant& val1, Variant& val2) { > > if(val1.isInt() && val2.isInt()) > > return new Variant(val1.toInt() + val2.toInt()); > > > > else if(val1.isFloat() && val2.isFloat()) > > return new Variant(val1.toInt() + val2.toInt()); > > else > > throw new RuntimeError(); > > } > > > > while on strict mode the generated code could be: > > > > int calc(int val1, int val2) { > > return val1 + val2; > > } > > > > So in this scenario is clear that strict mode performance and memory usage > > would be better. Code conversion code would be required only in some cases, > > example: > > > > calc(1, 5) // No need for casting > > > > calc((int) "12", (int) "15") // Needs casting depending on how the parser > > deals with it > > > > If my example is right it means strict would be better to achieve good > > performance rather than weak which is almost the same situation we have now > > with zval's. Also I think is wrong to say that casting will always take > > place on strict mode. > > > > So I have some questions floating on my mind for the coercive rfc. > > > > 1. Does weak mode could provide the required rules to implement a JIT with > > a sane level of memory and CPU usage? > > > > 2. I see that the proponents of dual weak/strict modes are offering to > > write a AOT implementation if strict makes it, And the impresive work of > > Joe (JITFU) and Anthony on recki-ct with the strict mode could be taken to > > another level of integration with PHP and performance. IMHO is harder and > > more resource hungry to implement a JIT/AOT using weak mode. With that > > said, if a JIT implementation is developed will the story of the > > ZendOptimizer being a commercial solution will be repeated or would this > > JIT implementation would be part of the core? > > > > Thats all that comes to mind now, and while many people doesn't care for > > performance, IMHO a programming language mainly targeted for the web should > > have some caring on this department. > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > --001a1133e5f21140cf050fc00faa--