[jit] Reduce refcounting of Types (#65345)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/65345

FooType::get() can return a const reference. Inconveniently, converting shared_ptr<FooType> to shared_ptr<Type> requires a copy & refcount bump, so to properly take advantage of this in unshapedType() we need to take a const Type& in isSubtypeOf(), which is good practice anyway -- don't require a shared_ptr if you don't need to take ownership.
ghstack-source-id: 140044165

Test Plan:
CI

perf says c10::unshapedType time decreased from 2.8% to 2.2% during static runtime startup, though I expect this to be generally beneficial.

Reviewed By: hlu1

Differential Revision: D31027361

fbshipit-source-id: 676feb81db9f74ad7b8651d8774f4ecb4cfa6ab8
This commit is contained in:
Scott Wolchok
2021-10-08 09:01:42 -07:00
committed by Facebook GitHub Bot
parent 1ae468a484
commit 2d885ab73d
69 changed files with 421 additions and 405 deletions

View File

@ -1117,7 +1117,7 @@ struct PythonPrintImpl {
// we cannot recover the type of unwrap_optional(None),
// using normal schema matching, so we route around this by rewriting
// the call to unwrap_optional(annotated(Optional[T], None))
if (node->input()->type()->isSubtypeOf(NoneType::get()) ||
if (node->input()->type()->isSubtypeOf(*NoneType::get()) ||
node->input()->mustBeNone()) {
auto input_type = OptionalType::create(node->output()->type());
stmt << "annotate(" << input_type->annotation_str(type_printer_)