[Cython] Exception check optimization

Robert Bradshaw robertwb at gmail.com
Thu May 30 04:25:55 CEST 2013


On Sun, May 26, 2013 at 10:04 AM, Nikita Nemkin <nikita at nemkin.ru> wrote:
> Hi,
>
> I wonder why is __pyx_filename (in exception check blocks)
> tracked dynamically? AFAIK it's impossible to split function
> body between multiple files (include only works at the top level),
> which makes filename a compile time constant for any given function.
>
> If the above is correct, __pyx_filename variable can be eliminated,
> saving at least 5 bytes per exception check (more on x64).

Probably because exception checks are heavy-weight enough that we
haven't bothered optimizing them at this level yet.

> On a related note, why is c_lineno enabled by default? So far I
> have only found one pretty rare case when it is useful - debugging
> autogenerated code in module init.

Well, it used to be much more useful back when Cython was less mature.

> I suspect that most people don't bother turning it off and get
> suboptimal code.

Again, raising exceptions is heavy-weight enough that I don't think
this is a significant performance issue. These days we certainly could
consider turning it off, because it is often irrelevant and a
deviation from how exceptions look in Python.

- Robert


More information about the cython-devel mailing list