STINNER Victor added the comment:

On my laptop, the revision introducing the performance regression is:
changeset:   101858:5a62d682636e
user:        Brett Cannon <>
date:        Fri Jun 10 14:37:21 2016 -0700
files:       Doc/library/os.rst Lib/test/ Misc/NEWS 
Issue #27186: Add os.PathLike support to DirEntry

Initial patch thanks to Jelle Zijlstra.

This change is unrelated to sorted(list). It looks more like a "random 
performance" caused by code placement:


According to perf record/perf report, the benchmark spends most of its time in 
PyObject_RichCompareBool() and long_richcompare():

Overhead  Command  Shared Object       Symbol
  41,98%  python   python              [.] PyObject_RichCompareBool
  35,36%  python   python              [.] long_richcompare
   8,52%  python   python              [.] listsort
   6,29%  python   python              [.] listextend
   5,31%  python   python              [.] list_dealloc

So I guess that the exact code placement of these two functions has a 
"signifiant" impact on performance. "Significant":

* rev b0be24a2f16c (fast): Median +- std dev: 15.0 us +- 0.1 us
* rev 5a62d682636e (slow): Median +- std dev: 16.3 us +- 0.0 us

The revision 5a62d682636e makes sorted(list) 9% slower.


Enabling PGO on compilation should help to get a more reliable code placement, 
and so more stable performances.

I suggest to close this issue as NOTABUG: ./configure --with-pgo should already 
fix this issue.


Python tracker <>
Python-bugs-list mailing list

Reply via email to