bpo-33058: Enhanced COUNT_ALLOCS to be ABI Compatible#6091
Closed
eduardo-elizondo wants to merge 3 commits into
Closed
bpo-33058: Enhanced COUNT_ALLOCS to be ABI Compatible#6091eduardo-elizondo wants to merge 3 commits into
eduardo-elizondo wants to merge 3 commits into
Conversation
Contributor
Author
|
Once accepted, I will add the News.d change. |
|
Doesn't this cause a change in behavior for code that modifies a type's |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This modifies the COUNT_ALLOCS build to be ABI Compatible. This means that there's no need to rebuild all extensions to be able to use this feature.
To make this ABI Compatible, I had to pull out the extra members from PyTypeObject and create another object - called "PyTypeObjectExt". Now, on every alloc/free, given a PyTypeObject we find/create the correct PyTypeObejctExt.
The only drawback is that on every alloc/free increase, this will now do an O(n) linked list traversal where n is the total number of different types seen so far. However, COUNT_ALLOCS is not meant to be a production build, thus the runtime perf hit won't matter as much - granted that this will allow us to gather object allocation data.
Furthermore, we don't expect the memory footprint to be that big as well, as this only allocates an object in memory once per every type.
Note: This also gets rid of a couple of places with extra bookkeeping as this doesn't modify the ref counts of the object themselves.
To test:
test.py:
// On a vanilla cpython:
https://bugs.python.org/issue33058