classification
Title: Update property_descr_set to use vectorcall if possible.
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: corona10, erlendaasland, kj, pablogsal, vstinner
Priority: normal Keywords: patch

Created on 2021-07-17 05:19 by corona10, last changed 2021-08-04 15:40 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
bench_property.py corona10, 2021-07-17 06:23
Pull Requests
URL Status Linked Edit
PR 27206 merged corona10, 2021-07-17 05:29
Messages (6)
msg397701 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-07-17 05:19
It shows a consistent 1-2% performance improvement.

Mean +- std dev: [property_base] 40.6 ns +- 0.6 ns -> [property_vectorcall] 40.0 ns +- 0.7 ns: 1.01x faster
msg397702 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-07-17 06:23
Oops sorry, it was the wrong benchmark, it will be faster.. ;)

Mean +- std dev: [property_base] 140 ns +- 5 ns -> [property_vectorcall] 125 ns +- 2 ns: 1.12x faster
msg397703 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-07-17 06:24
I updated the benchmark, and it shows 1.12x faster
msg397783 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-07-19 10:13
New changeset 635bfe8162981332b36cc556bac78e869af579c2 by Dong-hee Na in branch 'main':
bpo-44661: Update property_descr_set to use vectorcall if possible. (GH-27206)
https://github.com/python/cpython/commit/635bfe8162981332b36cc556bac78e869af579c2
msg397784 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-07-19 10:14
class Person:
    def __init__(self):
        self.__age = 0

    @property
    def age(self):
        return self.__age

    @age.setter
    def age(self, value):
        self.__age = value

p = Person()
p.age = 10 # Now become faster
msg398907 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-08-04 15:40
> Mean +- std dev: [property_base] 140 ns +- 5 ns -> [property_vectorcall] 125 ns +- 2 ns: 1.12x faster

Ah! That's better. If it was only 1.01x faster, I would say that it's not worth it. But 1.12x is worth it. Thanks for this optimization.
History
Date User Action Args
2021-08-04 15:40:50vstinnersetmessages: + msg398907
2021-07-19 10:14:43corona10setstatus: open -> closed
resolution: fixed
messages: + msg397784

stage: patch review -> resolved
2021-07-19 10:13:31corona10setmessages: + msg397783
2021-07-17 06:24:22corona10setmessages: + msg397703
2021-07-17 06:23:50corona10setfiles: - bench_property.py
2021-07-17 06:23:33corona10setfiles: + bench_property.py
2021-07-17 06:23:04corona10setmessages: + msg397702
2021-07-17 05:29:28corona10setkeywords: + patch
stage: patch review
pull_requests: + pull_request25741
2021-07-17 05:19:43corona10create