Hi Dmitry, On Wed, 23 Oct 2019 at 16:43, Dmitry Stogov <dmi...@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]