Skip to content

Avoid adding dependencies on immutable, immortal classes in the JIT #149217

@markshannon

Description

@markshannon

In the optimizer, the following pattern is fairly common:

   PyType_Watch(TYPE_WATCHER_ID, type);
   _Py_BloomFilter_Add(dependencies, type);

But for immutable, immortal types (which is a lot of the most common types) this is redundant as these types can never change, but increases the number of bits in the bloom filter raising the false positive rate.

The fix is simple: Factor out this pair of calls into a helper function and add a check there:

void watch_type(PyTypeObject *type, _PyBloomFilter *filter) {
    if (_Py_IsImmortal(type) && PyType_IsImmutable(type)) {
        return;
    }
    PyType_Watch(TYPE_WATCHER_ID, type);
   _Py_BloomFilter_Add(filter, type);
}

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetopic-JIT

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions