[issue47067] Add vectorcall for generica alias object

2022-03-21 Thread Dennis Sweeney


Dennis Sweeney  added the comment:


New changeset 1ea055bd53ccf976e88018983a3c13447c4502be by penguin_wwy in branch 
'main':
bpo-47067: Optimize calling GenericAlias objects (GH-31996)
https://github.com/python/cpython/commit/1ea055bd53ccf976e88018983a3c13447c4502be


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47067] Add vectorcall for generica alias object

2022-03-20 Thread penguin_wwy


penguin_wwy <940375...@qq.com> added the comment:

> You could also try replacing PyObject_SetAttrString with PyObject_SetAttr and 
> adding "__orig_class__" to the global strings with 
> Tools/scripts/generate_global_objects.py, probably for a later PR.

Already done via `make regen-global-objects`

Also, I found that `regen-global-objects` depends on `regen-deepfreeze`, which 
should be a bug. This causes the `regen-global-objects` to be executed with the 
compile task first, and it does not compile successfully at this point because 
of the new symbols(_Py_ID(__orig_class__)) added.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47067] Add vectorcall for generica alias object

2022-03-20 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

I profiled dict[str, int](a=1, b=2), and it looks like a decent chunk of time 
comes from PyUnicode_New as used by PyObject_SetAttrString.

You could also try replacing PyObject_SetAttrString with PyObject_SetAttr and 
adding "__orig_class__" to the global strings with 
Tools/scripts/generate_global_objects.py, probably for a later PR.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47067] Add vectorcall for generica alias object

2022-03-20 Thread Guido van Rossum


Guido van Rossum  added the comment:

@Dennis, if/when the PR looks good to you, you can merge it.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47067] Add vectorcall for generica alias object

2022-03-20 Thread penguin_wwy


penguin_wwy <940375...@qq.com> added the comment:

There is a small problem with the example:

```
d = dict[int]
```

should

```
d = dict[str, int]
```

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47067] Add vectorcall for generica alias object

2022-03-20 Thread Alex Waygood


Change by Alex Waygood :


--
nosy: +JelleZijlstra, gvanrossum, kj

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47067] Add vectorcall for generica alias object

2022-03-20 Thread penguin_wwy

penguin_wwy <940375...@qq.com> added the comment:

The point of bpo-40369 issue seems to be to provide vectorcall to the 
`GenericAliasType`, means vectorcall for `Queue[int]`

However, my idea is to add vectorcall to gaobject, like this:

```
d = dict[int]
d(a=1, b=2) <-- vectorcall
```

The idea came from my desire to implement different subclasses of a type when 
implementing some kind of factory model:

```
class ChildClassBuilder:
...

def set_type(self, t: Type):
self.t = t

def build():
instance = self.t()
...
return instance
```

In the case of high type-hint coverage, the `self.t` is often a gaobject.

Benchmark example:
```
def test():
d = dict[int]
for _ in range(100):
d(a=1, b=2)
```

Speedup 20% in my wsl2
```
opt:
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
10.0000.0001.7281.728 :1()
11.7281.7281.7281.728 test.py:4(test)

master:
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
10.0000.0002.2712.271 :1()
12.2712.2712.2712.271 test.py:4(test)
```

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47067] Add vectorcall for generica alias object

2022-03-19 Thread Dong-hee Na


Change by Dong-hee Na :


--
nosy: +Dennis Sweeney

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47067] Add vectorcall for generica alias object

2022-03-19 Thread Dong-hee Na


Dong-hee Na  added the comment:

We decided not to add it 
see bpo-40369

--
nosy: +corona10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47067] Add vectorcall for generica alias object

2022-03-19 Thread penguin_wwy


Change by penguin_wwy <940375...@qq.com>:


--
keywords: +patch
pull_requests: +30085
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/31996

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47067] Add vectorcall for generica alias object

2022-03-19 Thread penguin_wwy


New submission from penguin_wwy <940375...@qq.com>:

Although `ga_call` determines whether `origin` has a vectorcall, it needs to be 
unpacked the parameters that are already packed.
  /-> origin.vectorcall(unpacked)
MakeTpCall(packed) -> ga_call -> PyObject_Call
   \-> origin.tp_call

We can advance the `vectorcall` judgment to the `setup` phase.

ga_vectorcall -> origin.vectorcall

or

ga_make_tp_call -> _PyObject_MakeTpCall(packed argument) -> origin.tp_call

This will have no effect on tp_call, which still only needs to be packed once, 
while vectorcall does not need packed/unpacked

--
components: Library (Lib)
messages: 415556
nosy: penguin_wwy
priority: normal
severity: normal
status: open
title: Add vectorcall for generica alias object
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com