octave-maintainers
[Top][All Lists]
Advanced

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

Re: anonymous functions optimization - wanted for 3.4.0?


From: John W. Eaton
Subject: Re: anonymous functions optimization - wanted for 3.4.0?
Date: Sat, 11 Sep 2010 03:09:28 -0400

On 11-Sep-2010, Jaroslav Hajek wrote:

| On Fri, Sep 10, 2010 at 8:56 PM, Olaf Till <address@hidden> wrote:
| > On Fri, Sep 10, 2010 at 11:52:44AM +0200, Jaroslav Hajek wrote:
| >> hi all,
| >>
| >> attached is a patch that implements an interesting (IMHO) optimization
| >> of anonymous function handles. First a bit of theory:
| >> A number of anonymous function handles looks like this:
| >>
| >> h = @(par1, par2, ...) some_func (arg1, arg2, ....)
| >>
| >> where each argi is either a reference to some parj, or a constant, or
| >> a variable defined in the calling context. Such a function
| >> is called a "binder" because it merely takes some other function or
| >> handle and binds some of its parameters to certain values.
| >> Callback functions are often binders.
| >>
| >> Examples:
| >>
| >> @(x) size (x, 3)
| >> @(x, y) my_func (x, my_data, y)
| >>
| >> The attached patch optimizes calls to binders. When Octave constructs
| >> an anonymous handle, it attempts to detect if it's a binder. If so, it
| >> augments the handle with information how to transform the argument
| >> list and the "root" function's handle (or value). It then overrides
| >> the call sequence with a fast code that transforms the argument list
| >> and calls the root function. This eliminates the overhead of setting
| >> up an m-function, altering the call stack, and interpreting the
| >> function's body, making binders only incur small additive penalty to
| >> the root function's cost.
| >
| > If somewhere in a stack of "binders" occurs an error (reference to a
| > missing argument), will the error message show in which "binder" the
| > error occurs? Olaf
| >
| 
| The optimized code path is only taken if all arguments are given and
| thus no error can occur; otherwise, the normal interpreted code is
| used.

I have no objection to making a change like this for 3.4.0.

Thanks,

jwe



reply via email to

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