Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101958 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58990 invoked from network); 8 Mar 2018 17:52:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Mar 2018 17:52:51 -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.54 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.54 mail-it0-f54.google.com Received: from [209.85.214.54] ([209.85.214.54:56203] helo=mail-it0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A1/92-27785-07871AA5 for ; Thu, 08 Mar 2018 12:52:50 -0500 Received: by mail-it0-f54.google.com with SMTP id n136so6117275itg.5 for ; Thu, 08 Mar 2018 09:52:48 -0800 (PST) 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=NFyU26zbNJlzElRSTQzO5mOSMWlwj5E3HAbI5kmYq0w=; b=nzsn6jE1hqj4TC+EzipapSqODr6hg46+SnnaDKGSJcd6pDaJaaSTikki96QbuEmsgh XilYhpXNGThUv4AinA4T2WtJM1kfeqWO1Uon3Got/VVqs5scxvKHpg9QbG1VOhrJNQya ZLPOINUhkTOppBycxjxu1CJc3taCHRzpDkVvH1ahuFdJKgY4YhYBO0dgVIPzNLdZ0WJS +MYdAXqvhEnJdvj9NY451dGXOO9hjx7rKEjlwUpVE1r/gLd1Q2ycddFZMoH7UnLka0Af Pb+8d4jxS/Zt59gFrqXuuWtpUusqdZGeSlo5RMlWsLkyHhxXoS4thZ+3NQ3Ll8Z7EMCl K1ag== 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=NFyU26zbNJlzElRSTQzO5mOSMWlwj5E3HAbI5kmYq0w=; b=iVswYhGBsMHZe+yKyROYWVp8TdD+DwAQgJE+07UgWnZlfUrwKIXGIWrPTx8siuSkih LXE/ZPinRfpvqk5fNikonJ33wzw9ORcnhKgcxSdI1IIca1oWvAwFdUyCt53xTDhafBzY VGTU6k4E15haxfPWpvsrMh8OkdR2fEBq7aP6ht1df1e87yqZHUcGhgpzD9vJHcrqgZFQ DL6yOeV+USv08PF3BEgQdfhfX5UFOLN3FAs7xO/jDubRtZVePHb709ewpM/VQgRhAL8L xQSMoiEOGG7HqROnX9MnSUj/dRyUygrYmdGR6FoRiG5gjsuY2p8fgOba09axbCC1leKK 6pQg== X-Gm-Message-State: AElRT7FYSJFyIPfHl0U0J4joq26jmqhVWl8YpcgoTHiPmphFCJ8hA8z+ GciIoRqPIW7pM4yU+ztJ7eGNkUDqWgpOJDb0uUs= X-Google-Smtp-Source: AG47ELuTYMJvPZntUiCfFFQJfTZsTeJdLERSLy3cYGMWD4TN/RoYOe/jqBgQfCmI3R6uZB28UjMeRJ+gZPBhgNwjX6Y= X-Received: by 10.36.196.130 with SMTP id v124mr15249757itf.39.1520531564993; Thu, 08 Mar 2018 09:52:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.22.1 with HTTP; Thu, 8 Mar 2018 09:52:44 -0800 (PST) In-Reply-To: References: Date: Thu, 8 Mar 2018 18:52:44 +0100 Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: multipart/alternative; boundary="94eb2c05b8cacd219f0566ea57e2" Subject: Re: [PHP-DEV] Direct method call slower than method_exists() From: nikita.ppv@gmail.com (Nikita Popov) --94eb2c05b8cacd219f0566ea57e2 Content-Type: text/plain; charset="UTF-8" On Thu, Mar 8, 2018 at 6:41 PM, David Rodrigues wrote: > I have take note that a lot of projects (like Laravel) prefer uses > method_exists() than implements an empty function (that should be useful to > IDE when it is not annotated as an @method on class). > > For some reason, method_exists() will works faster than direct call when > method doesn't exists vs. a direct method call when method is empty. > > My benchmarks: > > Case #1: > * Direct call, empty method: > * Cycles by min. : 26.459.804 > > Case #2: > * Direct call, simple content (eg. is_bool(true)): > * Cycles by min. : 24.771.454 > - 6.38% slower than Case #1 > > Case #3: > * method_exists(), no method: > * Cycles by min. : 45.014.690 > - 70.12% faster than Case #1 > > Case #4: > * method_exists(), method exists with simple content: > * Cycles by min. : 18.068.555 > - 27.06% slower than Case #2 > > You will note that method_exists() will be more useful when method doesn't > exists (+70% faster), but worse in cases where it does (27% slower). Which > make that a hard decision, because you need "guess" the method declaration > usage when implements something like that. If case the method existence is > very low, then you will prefer method_exists(), which is bad for code > design. > > My suggestion here (that I don't know if could be applied as is): identify > empty methods and avoiding the execution (once that it will not do anything > anyway). So we could just implement empty methods without any problem. > > Maybe it could be done at this point and related: > https://github.com/php/php-src/blob/master/Zend/zend_ > language_parser.y#L725 > > -- > David Rodrigues Could you please provide the used benchmarking code? Nikita --94eb2c05b8cacd219f0566ea57e2--