Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107702 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 71708 invoked from network); 26 Oct 2019 10:48:52 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 26 Oct 2019 10:48:52 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id AF9662D201C for ; Sat, 26 Oct 2019 01:35:43 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Sat, 26 Oct 2019 01:35:43 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id u8so5112102iom.5 for ; Sat, 26 Oct 2019 01:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=e8FUw+JLON8XU6nATna/WlJn6mt5eYY4jNHa91FzWKk=; b=CGpmzVJfF3V8R/j5omDad3hlNmaWEDtkVq4G1R4T0kSVNcWDHAuBt+/BF8QUSBjDcL UQ6UnyRGr3uPthg9C7eZ7W2c7ZZEGzUJHFG2JGz1VG2WfrsVw/j3r9G+itDUqSRXDoTm 9H+5/aME6udzif6TlbGhmi2pF0JRI2raD79EkG4EPc9vYejO89Zd6mcEJdOSHis7VFPz iovr2Dnlv+1lKQBf5Y/CSF9r1CYwoyuD2NcNRPmsABS8mcS+I/umryvhgkl+9YU86A1f 2Z/4PRfm/WEpF5YD4VCuRkAywyQ7/fpa+1rGhBZCjOOrK2UV1rS2ru4VnuDLVl86Iazv jMCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=e8FUw+JLON8XU6nATna/WlJn6mt5eYY4jNHa91FzWKk=; b=WrLmdwKuiUlxYVsqRSugZ2j58HEDgMS+a309h4ACvK+54l0UxxVuO9GGGsJs3Yckxx zHOaDsJuM/6ZGuRnwuLko3GFAsiXaLzUZZkUgGh8MSik+QTdUEWFXmtv4rh07QAjh3m7 k+ClFnlJ2jqmVhBRgPIoRHAoHlyReZz8spTtbvykY75wlJl3yBIkSRHVvgCumCtOE9sG 8uKWYkp2MukOI37OWJox6OAzXwHkjPZF6yX/fmoUlTUj3ok3G0pjwP0tzdO7/LZy1ojY 4cUSGamEG1W/E3qxSsbUY0kpRFoYu8ueAfdc9ASS/PGQLnw/ACL+URZ8LN3TVRV+vwiv yjQQ== X-Gm-Message-State: APjAAAUyXNpKq6mU1KbVOQs1L9OtIhky6y09bmmV2ZMJ/cTN5lj5psMs zyCGZ5ciug2vdtQwrSbhkFTVIh1DtdVRwADw14w= X-Google-Smtp-Source: APXvYqzkILJf3FoF8gs1F583jwlfr2CG80X/pi3gjPjmXY4FbJiW4Mk/BZbd/KkUjhxJXwh7Lg8qTM8TGUznWjZ0z3k= X-Received: by 2002:a02:5103:: with SMTP id s3mr5955345jaa.45.1572078942305; Sat, 26 Oct 2019 01:35:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 26 Oct 2019 10:35:30 +0200 Message-ID: To: Rowan Tommins Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000ea41a90595cc26ff" X-Envelope-From: Subject: Re: [PHP-DEV] Re: [RFC] Union Types v2 From: benjamin.morel@gmail.com (Benjamin Morel) --000000000000ea41a90595cc26ff Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > I think this performance impact is a real concern; PHP is the only langua= ge > I know of which implements type checks entirely at run-time in production > code, and we should ask ourselves if that's definitely the right approach= . Would it be possible, at least in principle, to build a static analysis > tool which could prove that certain type checks would never fail, and pri= me > OpCache with code that leaves them out? As I understand it, this is how > Dart works: the compiler only emits run-time checks for assertions it can= 't > prove true by static analysis. I was wondering the same thing, especially in the light of preloading, where a lot of class/function definitions are known on startup. For example, doing: function x(): int {} function y(int $foo) {} y(x()); Should definitely not redundantly check the type of the y() parameter, if possible. Also, in the case of JIT, shouldn't type hints actually *improve* performance? =E2=80=94 Benjamin On Thu, 24 Oct 2019 at 14:47, Rowan Tommins wrote= : > Hi Dmitry, > > On Wed, 23 Oct 2019 at 16:43, Dmitry Stogov wrote: > > > Actually, I think PHP already took wrong direction implementing "typed > > references" and "type variance". > > Introducing more "typing", we suggest using it, but this "typing" comes > > with a huge cost of run-time checks. > > From 10% (scalar type hint of argument) to 3 times (typed reference > > assignment) performance degradation. > > Anyone may rerun my benchmarks > > https://gist.github.com/dstogov/fb32023e8dd55e58312ae0e5029556a9 > > > > > I think this performance impact is a real concern; PHP is the only langua= ge > I know of which implements type checks entirely at run-time in production > code, and we should ask ourselves if that's definitely the right approach= . > > Would it be possible, at least in principle, to build a static analysis > tool which could prove that certain type checks would never fail, and pri= me > OpCache with code that leaves them out? As I understand it, this is how > Dart works: the compiler only emits run-time checks for assertions it can= 't > prove true by static analysis. > > The simpler idea I had in this area was caching what type checks a value > had passed, either on each zval or perhaps just at the class level, so th= at > checking the same type again would be much faster, even if it was a compl= ex > union with multiple interfaces. > > Regards, > -- > Rowan Tommins > [IMSoP] > --000000000000ea41a90595cc26ff--