Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86479 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7512 invoked from network); 3 Jun 2015 15:13:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jun 2015 15:13:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.172 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.212.172 mail-wi0-f172.google.com Received: from [209.85.212.172] ([209.85.212.172:33967] helo=mail-wi0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 68/51-32628-EA91F655 for ; Wed, 03 Jun 2015 11:13:51 -0400 Received: by wibut5 with SMTP id ut5so106342760wib.1 for ; Wed, 03 Jun 2015 08:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=CbQV1CP7Ob8zAm+hgnqJNjFL3Vn+9+SQWUd2byUUp3w=; b=dnWzTexIPoI2CbMueropeZmEOAvtmipuiB0nuUoycwmIOGghkjaMoqK5mT0VDXCbVv QpJ7CHTLN4CKk5AxryylBaeklqDn+UPyJ/hKumGJcHXRcQQNDi35ZAkZqRB/O72JXXLW 09Lq1qUhEHfkDkU/4qSFiaejtoUlasBZMG5RwRahUHu8XiB+B4bbDe0596gDUmC4hReC uQWx/CvEJdHc1NKXzYN4eYzubijzfIRzuZW08x8+RwaA6pTqxKeEKu4jeGHFLn4S6/au mzySm3Q8TwVPLprdRnOQw1dkgwDST6o9ONoSGQwegmVLp4kyT1S1wQS9CEmds2f2d3nt VRIQ== X-Received: by 10.180.94.168 with SMTP id dd8mr41656387wib.76.1433344428253; Wed, 03 Jun 2015 08:13:48 -0700 (PDT) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.194.120.198 with HTTP; Wed, 3 Jun 2015 08:13:07 -0700 (PDT) In-Reply-To: <440717E2-B633-48FF-A629-DEC3E0D89B19@golemon.com> References: <440717E2-B633-48FF-A629-DEC3E0D89B19@golemon.com> Date: Wed, 3 Jun 2015 17:13:07 +0200 X-Google-Sender-Auth: q16jeUHiE6okkLYWRqYxv5fQ6As Message-ID: To: Sara Golemon Cc: Michael Wallner , "bishop@php.net" , PHP internals Content-Type: multipart/alternative; boundary=f46d044481677ca99c05179e8165 Subject: Re: [PHP-DEV] Method call overhead From: jpauli@php.net (Julien Pauli) --f46d044481677ca99c05179e8165 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Jun 3, 2015 at 4:29 PM, Sara Golemon wrote: > > > On Jun 3, 2015, at 00:50, Michael Wallner wrote: > > > >>> On 03 06 2015, at 05:30, Bishop Bettini wrote: > >> > >> My question though is on relative times. Method call overhead is > >> consistently 50% to 150% over a direct call. Is my experiment invalid= , > or > >> is this overhead expected? Is the overhead in the allocation, > >> deallocation, GC? > > > > I=E2=80=99suggest you use a tool like valgrind=E2=80=99s callgrind (and= visualize with > e.g. kcachegrind). > > > I'd also take variable function calling out of the picture (or at least, > have it as a separate dimension). Normal applications make pretty spare > use of variable functions (compared to actual direct calls), whereas your > benchmark uses them exclusively. So you've explicitly chosen the most > pessimistic path, and an unrepresentative one. > Yep, as I explain in [1] several [2] articles, direct calls are more efficient that variable ones, which makes the engine analyze your variable and look up for the function at runtime (whereas its done at compile time when direct call). Methods are heavier to trigger, because the engine needs to find the class, then to find the method in the class, to finally use it. The compiler can't pre-compute things, because the class may not exist yet and be rutime-autoloaded, which adds flexibility to the language, but also prevent us from optimizing things too deep. The lookups in method calls are done only the first time, those lookups are cached in the VM frame for reusage later. You may have a look at ZEND_INIT_STATIC_METHOD_CALL handler if you want to see what happens (for static calls). For functions, if the function is known at the time its called, and if the call is direct, then the process is fully optimized. [1] http://jpauli.github.io/2015/02/05/zend-vm-executor.html [2] http://jpauli.github.io/2015/01/22/on-php-function-calls.html Julien Pauli > > -Sara > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d044481677ca99c05179e8165--