octave-maintainers
[Top][All Lists]
Advanced

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

Re: cellfun performance


From: Jordi Gutiérrez Hermoso
Subject: Re: cellfun performance
Date: Tue, 9 Aug 2011 00:18:21 -0500

2011/8/8 Rik <address@hidden>:
> On 08/08/2011 12:39 AM, Jordi Gutiérrez Hermoso wrote:

>> 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.

I stepped through the code a little more carefully, and I can diagnose
this better now: both the "sin" and @sin ways of passing a function to
cellfun eventually end up in octave_builtin::do_multi_index_op through
polymorphic calls, but the function handle one takes longer to get
there because it first checks things about function handles, whereas
the "sin" call gets there faster due to the call to
symbol_table::find_function () that returns a more octave_value
representation than a function handle.

So the optimisation here should be simple, call a similar function for
function handles or other kinds of functions, but I cannot find
something in the Octave API for doing so.

> 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.

Octave function handles are fairly complicated classes and not just
pointers to static C functions in memory because there are many
different kinds of functions in Octave (built-in, user function, core
m-file, class member functions...) so a handle has to be able to
resolve which kind of function it's pointing to.

- Jordi G. H.


reply via email to

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