Re: Re: [RFC] Union Types v2
| From: | Rowan Tommins | Date: | Thu, 24 Oct 2019 12:47:08 +0000 |
| Subject: | Re: Re: [RFC] Union Types v2 | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-107656@lists.php.net to get a copy of this message | ||
Hi Dmitry,
On Wed, 23 Oct 2019 at 16:43, Dmitry Stogov <dmitry@zend.com> 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 language
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 prime
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 that
checking the same type again would be much faster, even if it was a complex
union with multiple interfaces.
Regards,
--
Rowan Tommins
[IMSoP]