Repository navigation
gh-145685: per-type method cache implementation #150160
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
36ffc5c
implement per type method cache
kumaraditya303 a4b07af
add micro benchmark
kumaraditya303 6b55b9d
fix issie with zero length arrays
kumaraditya303 c9bdf4b
fix for default build
kumaraditya303 bd59f2d
add comments
kumaraditya303 7416272
consistent function naming
kumaraditya303 258c0aa
Merge branch 'main' into mrocache
kumaraditya303 16ab4f9
formatting
kumaraditya303 7696234
add tests
kumaraditya303 a9d6917
fix _PyTypeCache_Invalidate wrapper
kumaraditya303 8d24e30
add comments
kumaraditya303 f62d1e9
fix tests for refleak check mode
kumaraditya303 728021c
Merge branch 'main' into mrocache
kumaraditya303 72dab63
address code review
kumaraditya303 27749ed
Merge branch 'main' of https://github.com/python/cpython into mrocache
kumaraditya303 cdf5643
fix MSVC compilation
kumaraditya303 b096009
fix bug causing assertion failure because find_name_in_mro can releas…
kumaraditya303 39f819b
fix bad merge of pystate.c
kumaraditya303 6da2741
use minsize as default length
kumaraditya303 ba4765f
📜🤖 Added by blurb_it.
blurb-it[bot] 5b3c0a0
fix ignored.tsv
kumaraditya303 28bdf4c
Merge branch 'main' of https://github.com/python/cpython into mrocache
kumaraditya303 1d96329
use unsigned int for version_tag
kumaraditya303 ae4b856
remove _PyTypes_AfterFork
kumaraditya303 4fbec93
fix docs
kumaraditya303 ff4525c
Merge branch 'main' of https://github.com/python/cpython into mrocache
kumaraditya303 66ed070
add type_cache_too_big to stats
kumaraditya303 c4a4fb3
fix missing header
kumaraditya303 9d6f460
add type_cache_resizes and type_cache_invalidations stats
kumaraditya303 2f6ccde
Merge branch 'main' of https://github.com/python/cpython into mrocache
kumaraditya303 80b3c33
Merge branch 'main' of https://github.com/python/cpython into mrocache
kumaraditya303 42a6ae8
remove lock free from title
kumaraditya303 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #ifndef PY_INTERNAL_TYPECACHE_H | ||
| #define PY_INTERNAL_TYPECACHE_H | ||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| #ifndef Py_BUILD_CORE | ||
| # error "this header requires Py_BUILD_CORE define" | ||
| #endif | ||
|
|
||
| #include "pycore_stackref.h" | ||
|
|
||
|
|
||
| #define _Py_TYPECACHE_MINSIZE (1 << 3) | ||
| #define _Py_TYPECACHE_MAXSIZE (1 << 16) | ||
|
|
||
| struct type_cache_entry { | ||
| PyObject *name; // name of the attribute or method, interned string, NULL if the entry is empty | ||
| PyObject *value; // borrowed reference or NULL | ||
| }; | ||
|
|
||
| // Per-type attribute lookup cache: speed up attribute and method lookups, | ||
| // see _PyTypeCache_Lookup(). | ||
| struct type_cache { | ||
| uint32_t mask; // mask for indexing into hashtable, i.e. size of hashtable is mask + 1 | ||
| uint32_t version_tag; // initialized from type->tp_version_tag | ||
| uint32_t available; // number of available entries in hashtable | ||
| uint32_t used; // number of used entries in hashtable | ||
| struct type_cache_entry hashtable[]; // hashtable entries, the total size is always power of 2 and at least _Py_TYPECACHE_MINSIZE | ||
| }; | ||
|
|
||
| struct _PyTypeCacheLookupResult { | ||
| _PyStackRef value; // value is a stack reference to the cached attribute or method, or NULL if not found | ||
| int cache_hit; // 1 if the cache entry is valid and matches the type's version tag, 0 otherwise | ||
| uint32_t version_tag; // version tag of the type when the value was cached | ||
| }; | ||
|
|
||
|
|
||
| extern void _PyTypeCache_InitType(PyTypeObject *type); | ||
| extern void _PyTypeCache_Insert(PyTypeObject *type, PyObject *name, PyObject *value); | ||
| PyAPI_FUNC(struct _PyTypeCacheLookupResult) _PyTypeCache_Lookup(PyTypeObject *type, PyObject *name); | ||
| PyAPI_FUNC(void) _PyTypeCache_Invalidate(PyTypeObject *type); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| #endif /* PY_INTERNAL_TYPECACHE_H */ | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.