octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cellfun performance


From: Rik
Subject: Re: cellfun performance
Date: Mon, 08 Aug 2011 10:16:57 -0700

On 08/08/2011 12:39 AM, Jordi Gutiérrez Hermoso wrote:
> On 6 August 2011 20:12, Rik <address@hidden> wrote:
> 
>> All of this suggests that cellfun should always be called with a
>> string argument since it will be faster than the equivalent function
>> handle and can potentially be much faster in common instances.
>>
>> Accordingly, I went ahead and made the change for the core Octave
>> functions in this changeset
>> (http://hg.savannah.gnu.org/hgweb/octave/rev/cefd568ea073).
> 
> I'm very troubled by this change, because it shouldn't be true that a
> string should be faster than a function handle. Also, changing all
> function handles of cellfun to strings in a way seems like a
> regression. 
I share your concern.  I wrote the first message about cellfuns because of
the disastrous performance with regard to functions defined as m-files.  In
this case, I would like to understand and improve the code, but it is also
important that core Octave functions be as fast as possible.  If that means
using string arguments, which is a cheap change, I will gladly do so.

Accordingly, I stepped slowly through the code to try to
> see what could happen.
> 
> My only guess is this: src/DLD-FUNCTIONS/cellfun.cc uses
> symbol_table::find_function which finds built-in functions.
> Polymorphically, this later turns into a different code path for
> built-in functions that seems slightly more efficient. For function
> handles, the code path is longer since the polymorphic call does
> things like check if the function handle refers to a file (!) on
> *each* function evaluation for each element of the cell, plus a couple
> more hops in the call stack through a number of polymorphic calls of
> octave_value::do_multi_index_op.
This is exactly what I had speculated with regard to m-files.  We should be
doing the function lookup once and getting a static reference to the actual
function code which we then use for the rest of the loop.  Someone with C++
expertise needs to address this.  In C one can have pointers to function
handles.  In C++ one can have pointers to method functions according to
this FAQ (http://www.parashift.com/c++-faq-lite/pointers-to-members.html)
but it is beyond my C++ abilities.

--Rik


reply via email to

[Prev in Thread] Current Thread [Next in Thread]