Skip to content

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

Closed

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

Activity

  1. added a commit that references this issue on May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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