You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#6108 did the bare minimum implementation of PyObject_LengthHint needed to compile and run in the Limited API - essentially "length hint is always optional so just fail to find it and return the default value".
That's fine in that it works and is no worse than the code that's in Cython 3.0 right now (which doesn't use length hint). However there's no reason not to do it right.
Except speed. For short data structures (which are not uncommon), even just trying to read the length hint from a Python attribute and unpacking it might take a major part of the time for building the entire C/C++ data structure. The slower the sequence of C-API calls for pre-sizing the container, the larger the data structures for which it degrades the performance.
However, it might actually be worth inlining the fast path of PyObject_Length() for CPython, i.e. checking sq_length and calling it to get a size. Most containers will provide it, and generators etc. won't have it.
Describe your issue
#6108 did the bare minimum implementation of
PyObject_LengthHint
needed to compile and run in the Limited API - essentially "length hint is always optional so just fail to find it and return the default value".That's fine in that it works and is no worse than the code that's in Cython 3.0 right now (which doesn't use length hint). However there's no reason not to do it right.
The implementation in Python is at https://github.com/python/cpython/blob/dd44ab994b7262f0704d64996e0a1bc37b233407/Objects/abstract.c#L92 and can likely be adapted.
The text was updated successfully, but these errors were encountered: