Disable has_relational_guards check for dict_tag optimization for now (#146232)

has_relational_guards evaluates to true almost always, and leads to a
slowdown in guards runtime

Pull Request resolved: https://github.com/pytorch/pytorch/pull/146232
Approved by: https://github.com/anijain2305
This commit is contained in:
Isuru Fernando 2025-02-03 03:22:35 +00:00 committed by PyTorch MergeBot
parent e3643e1e0e
commit 08b14936ae

View file

@ -2277,8 +2277,6 @@ class GuardManager {
return _root;
}
bool has_relational_guards();
std::string get_source() {
return _source;
}
@ -2411,7 +2409,7 @@ class GuardManager {
// to avoid early exits when dict_tag matches and the object is
// immutable.
new_tag = get_dict_version_unchecked(value);
matches_dict_tag = (new_tag == _dict_tag) && !has_relational_guards();
matches_dict_tag = (new_tag == _dict_tag);
}
}
@ -2634,10 +2632,6 @@ class RootGuardManager : public GuardManager {
_relational_guard_resetters.emplace_back(std::move(relational_guard));
}
bool has_relational_guards() {
return !_relational_guard_resetters.empty();
}
// Python visible API to check guard function.
bool check(py::handle value) {
return check_nopybind(value.ptr());
@ -2854,9 +2848,6 @@ class RootGuardManager : public GuardManager {
bool _init_local_state = false;
};
bool GuardManager::has_relational_guards() {
return _root->has_relational_guards();
}
/*
* Dicts are common in python code. Therefore, we handle guards for dicts
* differently and use PyDict_* APIs which are faster than PyObject_* APIs