[PyTorch] Change from unique_ptr to optional for RecordFunction state (#68397)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68397
Now that hot paths can avoid instantiating RecordFunction by using shouldRunRecordFunction, we can improve efficiency for profiling cases by avoiding a large heap allocation.
ghstack-source-id: 144235785
Test Plan:
1) Run //caffe2/caffe2/fb/high_perf_models/pytorch/benchmark_framework_overheads:cpp_benchmark before/after this diff with arguemnts --stressTestRecordFunction --op empty.
Before: P467891381
After: P467902339
2) Run without --stressTestRecordFunction to verify no regression in the regular dispatcher path.
Before: P467902381
After: P467902403
Reviewed By: chaekit
Differential Revision: D32448365
fbshipit-source-id: 2d32a3bd82c60d2bb11fc57bb88bf3f02aa3fa25