-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
gh-148276: Optimize object creation and method calls in the JIT by resolving __init__ at trace optimization time #148277
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,6 +134,21 @@ dummy_func(void) { | |
| assert(!PyJitRef_IsUnique(value)); | ||
| } | ||
|
|
||
| op(_GUARD_TYPE_VERSION_LOCKED, (type_version/2, owner -- owner)) { | ||
Fidget-Spinner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert(type_version); | ||
| if (sym_matches_type_version(owner, type_version)) { | ||
| ADD_OP(_NOP, 0, 0); | ||
Fidget-Spinner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| PyTypeObject *type = _PyType_LookupByVersion(type_version); | ||
| if (type) { | ||
| if (sym_set_type_version(owner, type_version)) { | ||
| PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type); | ||
| _Py_BloomFilter_Add(dependencies, type); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| op(_STORE_ATTR_INSTANCE_VALUE, (offset/1, value, owner -- o)) { | ||
| (void)offset; | ||
| (void)value; | ||
|
|
@@ -1027,9 +1042,25 @@ dummy_func(void) { | |
| } | ||
|
|
||
| op(_CHECK_AND_ALLOCATE_OBJECT, (type_version/2, callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) { | ||
| (void)type_version; | ||
| (void)args; | ||
| callable = sym_new_not_null(ctx); | ||
| PyTypeObject *type = _PyType_LookupByVersion(type_version); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to reduce usage of this as it's going to be slow to make thread-safe on FT. Also it's quite fragile and redundant, considering we can already record types in the JIT tracer. I will push a change to use recorded values instead of reverse-lookup ones here. |
||
| if (type) { | ||
| PyHeapTypeObject *cls = (PyHeapTypeObject *)type; | ||
| PyObject *init = FT_ATOMIC_LOAD_PTR_ACQUIRE(cls->_spec_cache.init); | ||
| if (init != NULL && PyFunction_Check(init)) { | ||
| // Propagate the __init__ function so _CREATE_INIT_FRAME can | ||
| // resolve the code object and continue optimizing. | ||
| callable = sym_new_const(ctx, init); | ||
| PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type); | ||
| _Py_BloomFilter_Add(dependencies, type); | ||
| } | ||
| else { | ||
| callable = sym_new_not_null(ctx); | ||
| } | ||
| } | ||
| else { | ||
| callable = sym_new_not_null(ctx); | ||
| } | ||
| self_or_null = sym_new_not_null(ctx); | ||
| } | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.