-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-34100: compile: Re-enable frozenset merging #10760
Conversation
Py_INCREF(t); | ||
Py_DECREF(key); | ||
return t; | ||
} | ||
|
||
// We registered o in c_const_cache. | ||
// When o is a tuple or frozenset, we want to merge it's | ||
// items too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to do it backward?
- First merge items
- Then merge the container
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it just make program more complicated. We need to check the container is not registered yet before merging items. So we need to generate key tuple containing the container object first anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to add the newly merged container to the cache rather than modifying the existing cache entry in-place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible. This commit rewrites tuple merging without in-place modify of tuple and key.
2eb1471
But I'm not sure avoiding in-place edit is so important...
We have similar code already.
https://github.com/python/cpython/blob/master/Objects/codeobject.c#L47-L95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/python/cpython/blob/master/Objects/codeobject.c#L47-L95
Oh wow, this code is even worse: it modify the "immutable" arguments of PyCode_New() :-(
I wrote an implementation of my proposal (merge items, then the container): PR #10762. |
When there are 100 same 5-tuples, my PR makes key objects 100+5 times. In your PR, key object |
Travis CI is unhappy:
|
I wrote PR #10762 for the correctness more than for performance :-) Is it possible to measure the overhead of merge_consts_recursive() with a benchmark? |
Performance difference is relatively small because parser is slower than compiler. |
Oh thanks for the benchmark. Would you mind to run the benchmark on your PR as well? |
40c2fb7
to
86d305e
Compare
This benchmark measures only tuples and floats. So my PR (only affects frozenset) doesn't have overhead.
|
And when I removed merge_const_recursive:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. "./python -m test test_compile -R 3:3" pass.
I have no strong preference between your PR and my PR, as soon as the tests pass :-)
https://bugs.python.org/issue34100