Opened 7 years ago

Last modified 7 years ago

#182 new enhancement

Inline iterator utility functions

Reported by: dagss Owned by: somebody
Priority: minor Milestone: wishlist
Component: Optimization Keywords:


Filing this as it's an idea and I "need" it, but it is far out and really low priority.

Consider this snippet:

cdef inclusive_range(low, high):
    newhigh = high + 1
    return range(low, high)

Now, inlining this Cython-side could mean very much to performance. So the proposal is: If the iterator in a for-loop calls a cdef function, inspect whether there is a) only one possible return value outside of any branches, and b) if it is a Cython "magic loop function". If so, inline it in Cython.

(There's always the danger of this being too magic *shrug*)

Change History (3)

comment:1 Changed 7 years ago by dagss

  • Type changed from defect to enhancement

comment:2 Changed 7 years ago by scoder

I actually find this "too magic", as it handles a very special case that looks much more general to a user.

It would be better to a) have a more general typing step for functions based on their return value, and lacking that for now, b) allow something like

cdef xrange inclusive_range(low, high):

return xrange(...)

comment:3 Changed 7 years ago by dagss

Ah, good idea. Alternatively a decorator, @cython.returnsmagiciterator or similar. I forgot that magicness can always be removed by adding explicit declarations :-) (complexity cannot though)

Note: See TracTickets for help on using tickets.