[Python-ideas] Exploiting type-homogeneity in list.sort() (again!)
Elliot Gorokhovsky
elliot.gorokhovsky at gmail.com
Thu Mar 9 10:30:05 EST 2017
On Thu, Mar 9, 2017 at 3:04 AM Barry Scott <barry at barrys-emacs.org> wrote:
>
> So you do O(nlogn)*2 pointer compares with my suggestion it seems? Which
> is smaller the O(n) pointer checks?
>
Not sure what you mean here... pretty sure your inequality is backwards?
Look -- the point is, we already *do* the pointer checks during every
compare. That's the current implementation. I believe my benchmarks are
sufficient to prove that my patch is much faster than the current
implementation. Which makes sense, because we do one type check per object,
as opposed to something like log n per object, and we do them all at once,
which I do believe is faster than doing them across calls.
Now, you're not entirely wrong -- the current implementation doesn't do the
type checks as efficiently as it could. Specifically, it does them once in
PyObject_RichCompareBool, and then *again* in ob_type->tp_richcompare
(which it has to for safety: ob_type->tp_richcompare doesn't know the
arguments have already been type-checked!) You could totally define
optimized compares that do the type-checks more efficiently, and you would
see a benefit, just not nearly as extreme as the benefit I demonstrate.
Thanks again for your feedback!
Elliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170309/bd7ea15f/attachment.html>
More information about the Python-ideas
mailing list