Commit 2d5c312
gh-103951: enable optimization for fast attribute access on module subclasses
This patch relax specialization requirements from
``PyModule_CheckExact(op)`` to
``Py_TYPE(op)->tp_getattro != PyModule_Type.tp_getattro``.
Benchmarks:
```py
import pyperf
import b
import c
runner = pyperf.Runner()
runner.timeit('b.x', 'b.x', globals=globals())
runner.timeit('c.x', 'c.x', globals=globals())
```
```py
x = 1
```
```py
import sys, types
x = 1
class _Foo(types.ModuleType): pass
sys.modules[__name__].__class__ = _Foo
```
On the main:
```
$ python a.py -q
b.x: Mean +- std dev: 50.2 ns +- 2.7 ns
c.x: Mean +- std dev: 132 ns +- 7 ns
```
With the patch:
```
$ python a.py -q
b.x: Mean +- std dev: 52.9 ns +- 3.6 ns
c.x: Mean +- std dev: 52.6 ns +- 2.7 ns
```
Co-authored-by: Nicolas Tessore <[email protected]>1 parent 260843d commit 2d5c312
File tree
6 files changed
+12
-3
lines changed- Include/internal
- Misc/NEWS.d/next/Core_and_Builtins
- Python
- Tools/cases_generator
6 files changed
+12
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
19 | 25 | | |
20 | 26 | | |
21 | 27 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2108 | 2108 | | |
2109 | 2109 | | |
2110 | 2110 | | |
2111 | | - | |
| 2111 | + | |
2112 | 2112 | | |
2113 | 2113 | | |
2114 | 2114 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1143 | 1143 | | |
1144 | 1144 | | |
1145 | 1145 | | |
1146 | | - | |
| 1146 | + | |
1147 | 1147 | | |
1148 | 1148 | | |
1149 | 1149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
598 | 598 | | |
599 | 599 | | |
600 | 600 | | |
| 601 | + | |
601 | 602 | | |
602 | 603 | | |
603 | 604 | | |
| |||
0 commit comments