classification
Title: MRO computation could be faster
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: inada.naoki, pitrou, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2017-12-19 19:54 by pitrou, last changed 2017-12-20 14:58 by pitrou. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4932 merged pitrou, 2017-12-19 19:56
Messages (5)
msg308674 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-12-19 19:54
MRO computation involves a complicated merge calculation over several lists.  But, for the simple (common) case where a class has a single base, the computation could be much simpler: take the base's MRO and prepend the derived class.
msg308675 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-12-19 20:00
Benchmarks:

* before:

$ ./env-orig/bin/pyperf timeit "class Test: pass"
.....................
Mean +- std dev: 9.51 us +- 0.17 us

* after:

$ ./env/bin/pyperf timeit "class Test: pass"
.....................
Mean +- std dev: 8.89 us +- 0.09 us
msg308733 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-12-20 14:06
LGTM in general. But mro() returns a list.

"class Test: pass" is a trivial case. What are results if the class has a parent?
msg308734 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-12-20 14:15
Benchmarks with a parent:

* Before:

$ ./env-orig/bin/pyperf timeit -s "from unittest import TestCase" "class Test(TestCase): pass"
.....................
Mean +- std dev: 10.4 us +- 0.1 us

* After:

$ ./env/bin/pyperf timeit -s "from unittest import TestCase" "class Test(TestCase): pass"
.....................
Mean +- std dev: 9.89 us +- 0.12 us
msg308737 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-12-20 14:58
New changeset 1f1a34c3145781628e10534440017b3b43211a60 by Antoine Pitrou in branch 'master':
bpo-32379: Faster MRO computation for single inheritance (#4932)
https://github.com/python/cpython/commit/1f1a34c3145781628e10534440017b3b43211a60
History
Date User Action Args
2017-12-20 14:58:51pitrousetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-12-20 14:58:23pitrousetmessages: + msg308737
2017-12-20 14:15:19pitrousetmessages: + msg308734
2017-12-20 14:06:11serhiy.storchakasetmessages: + msg308733
2017-12-19 20:00:20pitrousetmessages: + msg308675
2017-12-19 19:56:53pitrousetnosy: + vstinner, inada.naoki, serhiy.storchaka
2017-12-19 19:56:32pitrousetkeywords: + patch
stage: patch review
pull_requests: + pull_request4825
2017-12-19 19:54:59pitroucreate