Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99398 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3931 invoked from network); 6 Jun 2017 12:43:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jun 2017 12:43:18 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.41 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.41 mail-it0-f41.google.com Received: from [209.85.214.41] ([209.85.214.41:36365] helo=mail-it0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0C/9E-27119-463A6395 for ; Tue, 06 Jun 2017 08:43:17 -0400 Received: by mail-it0-f41.google.com with SMTP id m47so91409505iti.1 for ; Tue, 06 Jun 2017 05:43:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=H6L33FWbIr5g8vZy/Q8GlkGk8i/OvxduNgNiFdp42xA=; b=ZXiz5dT7vMdQuK3NVHYs4Dfgr94kKyRXFAR3S89Fm/8UrFiBC0yKLtbPt7JVChcygT Ez9S4zvbS/MaH7foTOIrSWxgPDNoqkwZ/Xm9EPMk2/aM0qSEh0aG3Is3WcsoH8+6w+66 PNnyiREJThDH+E7a6yYicmNheN3VZwnFC9iib1ebsAqQGkA9gd0bWypZrYIjcEuNzR3c cNqgMtIue6bcq0Kpyxq+cIig1etUH/dn8X1mWNnjUqj61tAH0OXhgK/fo/AI0XrTL1Bt qGXfy5W/B52cjjiGZ23SdrUQ54mvpJbtHBQ8mCSoI7lm1zgduIs0VCOiNZ3eAGI5wyD3 g3hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=H6L33FWbIr5g8vZy/Q8GlkGk8i/OvxduNgNiFdp42xA=; b=uM9P9FM3PEEVHN8N5IqBngwknmTcZUd1Sjf00GLkw2kZK7XwbtEK5G8IqBU5RqP4Ve +w2UdtleNkwf0xBLnbDvRe+E8t9RySjcqkJFeWAQQQdMdfBe9k7U0gjrnraU/ta0l0fY TF5jeWsMkiGeb7ojLAZiCZqKjswWUoaqAoXbDJlnk0Vl7QpU1JmCbWWlWRX3gR8XZGX9 n580sitRDjoW9RZxXmid+QZjnItyaAiIn02yXHejDKTC8peND+1k4SueEl4561uXwQV2 fubpiN23W2CAzSh41C1oNvwjdO2h5YDUbBDkHVD6w0UBS5FRgP9ikqplCWinzvafMc41 sZNQ== X-Gm-Message-State: AODbwcCOeWWcbh0tlFR1u601oqxo7uBU5Wb1QiHEdn8NbJZhxn9221Xd eVA1BPHQc3RShMkSa/iF49/IiGPFJw== X-Received: by 10.107.24.4 with SMTP id 4mr23515664ioy.169.1496752993806; Tue, 06 Jun 2017 05:43:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.12.158 with HTTP; Tue, 6 Jun 2017 05:43:13 -0700 (PDT) In-Reply-To: <5313411f-40b4-58c6-83a8-7e813526f2a7@tekwire.net> References: <5313411f-40b4-58c6-83a8-7e813526f2a7@tekwire.net> Date: Tue, 6 Jun 2017 14:43:13 +0200 Message-ID: To: =?UTF-8?Q?Fran=C3=A7ois_Laupretre?= Cc: PHP internals Content-Type: multipart/alternative; boundary="94eb2c05ae588352ec055149f606" Subject: Re: [PHP-DEV] Proposing inclusion of PCS in the 7.2 core distribution From: nikita.ppv@gmail.com (Nikita Popov) --94eb2c05ae588352ec055149f606 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jun 5, 2017 at 7:46 PM, Fran=C3=A7ois Laupretre wrote: > Hi, > > PCS provides a fast and easy mechanism to mix C and PHP code in PHP > extensions (more about PCS at http://pcs.tekwire.net). Thanks to the PHP > 7 performance improvement and the inclusion of opcache in the core, a lot > of existing non-performance-critical extension code may now be converted = to > PHP without significant performance loss (this must be measured case by > case, of course, but tests show that opcode-cached PHP code is often fast= er > than C). > > Another motivation is the lack of extension maintainers. It may be comple= x > to convert a C extension to PHP but, once it's done, maintenance becomes > much easier. > > As one of PCS goals is to allow converting parts of existing core > extensions to PHP, it seems natural to initiate the movement by an > inclusion of PCS in the core distribution. Then, I and others will start > proposing conversions of existing code. IMO, the PDO generic layer is a > perfect candidate, but there are many others. > > Converting existing C code to PHP is not the only usage. With PCS, adding > an OO layer to a function-only extension becomes an easy task. Sara > recently told about a curl OOP layer (https://gist.github.com/sgole > mon/e95bfc34d34c4f63fa953ee9294ae02c). Using PCS, adding such PHP code on > top of the curl extension would take less than one hour. > > I hadn't proposed this so far because the 'cache_key' operation currently > proposed for 7.2 is a pre-requisite, as PCS exposes the PHP code it manag= es > via a stream wrapper. > > So, please give me your thoughts. Suggestions of potential candidates to > be rewritten from C to PHP are welcome too. > Hi, First of all: I think the ability to implement parts of PHP extensions in PHP is extremely important and will be a game changer in our ability to maintain and improve our standard library. There are essentially only two good reasons for implementing functionality in C: One is performance, the other is FFI. Unfortunately, the requirement to use C for everything inside an extension means that we write a large amounts of C code that does not fall into either of those categories. The resulting code is hard to maintain, often subtly buggy and usually not consistent with ordinary userland PHP code. Typical issues we see all the time are bad or completely absent serialization support, lack of circular garbage collection, crashes when the object is improperly initialized and bugs appearing when internal classes are extended. On top of that, implementing certain functionality in C actually makes the resulting code slower than equivalent PHP code. While our virtual machine is highly optimized, our internal APIs are often not, or not typically used in their most efficient form. One case where internal code loses are invocations of userland callbacks. Another is access to properties. The current situation also has a large and somewhat hidden impact on our API design. Due to the large maintenance burden that implementing "proper" APIs imposes on us, we tend to go with the simplest possible API. Usually this means that we end up directly exposing C binding APIs, even if they are a very bad fit for PHP. As already noted in this thread, the current curl API is such an example. (I know that some people will argue that its better to expose simple procedural APIs rather than fancy object oriented APIs -- however, that's a choice that should be made based on technical arguments, not due to technical limitations.) Some people have mentioned that this is better solved by shipping the PHP code separately using composer. While this may be viable for 3rd party extensions (and may be preferable if they have large fractions of PHP code), this option does not exist for our standard library. We can hardly tell people that they should go install a composer package in order to make use of some APIs in our standard library. Anyway, to get back to the topic of PCS. First, I would recommend to target PHP 7.3 for this change. Feature freeze for 7.2 is in a bit over a month and I think we'll want to make some non-trivial changes to how this works if we integrate it in PHP. If added to PHP, I think this should be integrated into the core, rather than being an extension. Here are some random thoughts: 1. As far as I understand, PCS relies on autoloading. There are two issues here: First, autoloading does not register symbols prior to autoloading. This means that functions like get_defined_classes() will not behave as expected. Second, autoloading does not support functions. I think both of these problems can be solved with some up-front symbol analysis. Lazily compiling internal functions should not run into any of the problems we have with userland function autoloading. 2. It has already been mentioned in the thread, but what seems to lack right now is a good way of integrating PHP and C portions. As far as I understand, PCS allows you to write an entire class in PHP, but it does not allow you to offload parts of the functionality to C without exposing additional public APIs. I think there are two things we can do here: a) Provide a mechanism that makes certain functions only available inside extension PHP code. This would allow exposing some private PHP functions which are only used in the internal implementation of the extension. b) Allow binding some methods specified in PHP to an internal implementation. The way this works in HHVM is that the PHP file contains just a signature, with an attribute that signifies that an internal implementation will be bound to that function: class Bar { <<__Native>> function foo($args); } This would be useful for other reasons as well. In particular, this could become a replacement for the existing arginfo-based signature specification, which is somewhat limited and causes discrepancies with userland classes. For example, arginfo does not support default values. Regards, Nikita --94eb2c05ae588352ec055149f606--