[dynamo][guards-cpp] Early return in DictGuardManager for empty dicts (#123787)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/123787
Approved by: https://github.com/jansel
ghstack dependencies: #123773
This commit is contained in:
Animesh Jain 2024-04-10 21:32:40 -07:00 committed by PyTorch MergeBot
parent b0b7aa201c
commit 2e6871f924

View File

@ -1934,6 +1934,11 @@ class DictGuardManager : public GuardManager {
return false;
}
// Early return
if (_size == 0) {
return true;
}
// Invokes the base class's check_nopybind method. We permit a limited set
// of leaf guards and accessors within the DictGuardManager framework.
// Integrating certain guards or accessors directly within the
@ -1987,6 +1992,11 @@ class DictGuardManager : public GuardManager {
false, "len(" + get_source() + ") != " + std::to_string(_size), 0);
}
// Early return
if (_size == 0) {
return GuardDebugInfo(true, 0);
}
// Invokes the base class's check_nopybind method. We permit a limited set
// of leaf guards and accessors within the DictGuardManager framework.
// Integrating certain guards or accessors directly within the
@ -2148,6 +2158,11 @@ class DictSubclassGuardManager : public DictGuardManager {
return false;
}
// Early return
if (_size == 0) {
return true;
}
if (!GuardManager::check_nopybind(obj)) { // NOLINT
_fail_count += 1;
// No need to shuffle the child guards, just return.
@ -2199,6 +2214,11 @@ class DictSubclassGuardManager : public DictGuardManager {
false, "len(" + get_source() + ") != " + std::to_string(_size), 0);
}
// Early return
if (_size == 0) {
return GuardDebugInfo(true, 0);
}
GuardDebugInfo debug_info =
GuardManager::check_verbose_nopybind(obj); // NOLINT
if (!debug_info.result) {