New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize _PyFunction_FastCallDict() for **kwargs #73504
Comments
Example: def func(x, y):
print(x, y)
def proxy2(func, **kw):
func(**kw)
def proxy1(func, **kw):
proxy2(func, **kw) The "proxy2(func, **kw)" call in proxy1() is currently inefficient: _PyFunction_FastCallDict() converts the dictionary into a C array [key1, value1, key2, value2, ...] and then _PyEval_EvalCodeWithName() rebuilds the dictionary from the C array. Since "func(*args, **kw)" proxies are common in Python, especially to call the parent constructor when overriding __init__, I think that it would be interesting to optimize this code path. I first expected that it was a regression of FASTCALL, but Python < 3.6 doesn't optimize this code neither. |
Since mutating kw dict shouldn't affect caller's dict, caller and callee can't share the dict. One possible optimization is using PyDict_Copy() to copy the dict. |
Keys are strings (even interned strings), and hashes are cached. In most cases kw is empty or very small. I doubt any optimization can have significant effect. |
New changeset fcba9c9d987b by Victor Stinner in branch 'default': |
INADA Naoki: "Since mutating kw dict shouldn't affect caller's dict, caller and callee can't share the dict." Oh, I knew that, it's not the first time that I propose to implement this optimization and that I got this answer !? So I added a comment for myself, to remind me not to propose this optimization anymore :-D I close this issue. Serhiy Storchaka: "In most cases kw is empty or very small. I doubt any optimization can have significant effect." I have no opinion on Naoki's optimization idea. Naoki: Feel free to implement your idea to measure the speedup, but please open a new issue for that if you consider that it's worth it. FYI Naoki and me started to list ideas to optimize CPython 3.7: |
Why Roundup Robot spams with empty or almost empty messages? |
Serhiy Storchaka: "Why Roundup Robot spams with empty or almost empty messages?" It smells like the migration to GitHub started :-) |
New changeset 2c145e9eda756aa2001282d7c016e740dd00a2d7 by Victor Stinner in branch 'master': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: