Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101957 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56973 invoked from network); 8 Mar 2018 17:41:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Mar 2018 17:41:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.179 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.223.179 mail-io0-f179.google.com Received: from [209.85.223.179] ([209.85.223.179:43288] helo=mail-io0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 88/22-27785-1E571AA5 for ; Thu, 08 Mar 2018 12:41:53 -0500 Received: by mail-io0-f179.google.com with SMTP id l12so525112ioc.10 for ; Thu, 08 Mar 2018 09:41:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=RpXGuBduhkTh7TVoaW3f5dc9v6kmUhPfbmYlrAmFWwE=; b=nWBF1c60xTUpN4StN5awhMm7+x7N4RNwNxJFt0v5+ulx5aMuxcdbZASTHn6pfiuI63 G6hWtB/pJeoqkbO6dPvxFxV4lZfQhBT2kwvtUal2wpiuB2K0n4B8QNzYgI7VCdJikeYz bekf5yVBvM4bvxPDIBmEuP8oosNA1HM0CAf3JmEW8ncJyRHotbvQ+PpFHBFFvRyoZv6u 1S+pLLf4kN4CvcHTo00mioiin90dzz2uNunq14Gm4LZ9/B926ZR/RVe80oU8ijzg7pCF G7HK2UYtHWh93d1/TlbIqjegut8ps/p+iP8bMI2ruMrt3w+L2Tfrp4OAoJufJbCqRSae LSgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=RpXGuBduhkTh7TVoaW3f5dc9v6kmUhPfbmYlrAmFWwE=; b=lyexgDw2i0N9ok8bST2h4sRnXlGnAo/ghFjo8bTfn7z4QT1AQSAHXikFimSuLgCt/m /quwMC7UBLwMSbRAUUFRRgGJPs5u1T8hkCVjKfGzqP1dGAYgu4JXjGeM6KgMgQqpwHRG KOu2r1ZCKVkwNOm9cj1d2OXNHV4YHo0BzpOeCfF0TILfvFdagcMC7lJxmLQ9z2rK+s8k 3nh8rD1+fhiDbnqMSr8NNNO1rNrj8f3MEbf5ECo7K7E/VUFajRR12aFIfDcujB3+YteG ADqwg/UgA3V5TAfuTUHAqQ0QxDd/v9EkztCJ3LO3+hV5KEUlaXWN3UEswWhD6cMHJtGD iRow== X-Gm-Message-State: APf1xPAgxSnjDU1zMNIiBXvaCiqTA/P5nUucVkh+mlg/v1zwj73igOQF VKHvtEVmRmW3huCLUAF2JnU6wBBFpqAM9dManh3y7g== X-Google-Smtp-Source: AG47ELts59gon7cx/y4jndSJGetyZOP6kP+dKa008sBEbkE2k3lG1BBM8pB5hQ/Sx2hBAWZgoPr+ifB7Ffor0fMmprg= X-Received: by 10.107.59.130 with SMTP id i124mr31544759ioa.129.1520530910595; Thu, 08 Mar 2018 09:41:50 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.118.74 with HTTP; Thu, 8 Mar 2018 09:41:30 -0800 (PST) Date: Thu, 8 Mar 2018 14:41:30 -0300 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="001a114f8758cbcf350566ea3062" Subject: Direct method call slower than method_exists() From: david.proweb@gmail.com (David Rodrigues) --001a114f8758cbcf350566ea3062 Content-Type: text/plain; charset="UTF-8" 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 --001a114f8758cbcf350566ea3062--