Repository: pytorch
Issue: Regression in Python arg parser performance.
Labels: module: performance,module: bootcamp,triaged

## 🐛 Bug

PyTorch implements its own argument parser to call into C++ from Python. https://github.com/pytorch/pytorch/pull/51350 regressed this component under certain circumstances. This is a good bootcamp task if you're interested in how the Python and C++ layers interact.

## To Reproduce

[This script](https://gist.github.com/robieta/2b5d5b4286d29ef5f09870a924cb0f77) will collect instruction counts and wall times; substitute the following to measure this regression:

```
# =============================================================================
# == PR specific code =========================================================
# =============================================================================
COMMIT_0 = "816646bd6f5a3f4d03c1f00c0e7513f5abfc6e11"
COMMIT_1 = "70d0aab7bdf8e8e13c865afabfb63ce84d30c027"
make_timer = lambda: Timer("torch.empty((1,))")
```

This assumes a conda environment for each commit. [This bash function](https://gist.github.com/robieta/cdfc9137522dd6cc3f80452159e20cb1) can automate the creation of these environments. (However feel free to use a different workflow if you prefer.)

```
$ python bootcamp.py
40 / 40
<torch.utils.benchmark.utils.common.Measurement object at 0x7fcdaeff23d0>
torch.empty((1,))
  Median: 1.52 us
  IQR:    0.12 us (1.47 to 1.59)
  6219 measurements, 1 runs per measurement, 1 thread

<torch.utils.benchmark.utils.common.Measurement object at 0x7fcdaeff2210>
torch.empty((1,))
  Median: 1.66 us
  IQR:    0.11 us (1.62 to 1.73)
  5631 measurements, 1 runs per measurement, 1 thread

516663
592160

<torch.utils.benchmark.utils.valgrind_wrapper.timer_interface.FunctionCounts object at 0x7fcdaf0ceed0>
   10000  Objects/object.c:_PyObject_GenericGetAttrWithDict
    9600  Objects/typeobject.c:PyType_IsSubtype
    9400  Objects/abstract.c:PyObject_IsInstance
    8000  Objects/typeobject.c:_PyType_Lookup
    6400  Objects/descrobject.c:getset_get
    5600  build/../torch/csrc/utils/python_numbers.h:THPUtils_checkIndex(_object*)
    4600  Objects/object.c:_PyObject_LookupAttr
    3800  Objects/abstract.c:PySequence_GetItem
    3600  build/../torch/csrc/utils/tensor_numpy.cpp:torch::utils::is_numpy_int(_object*)
     ...
     600  Objects/typeobject.c:object_get_class
     195  ???:_int_malloc
     -13  ???:_int_memalign
     -85  ???:_int_free
    -200  build/aten/src/ATen/core/TensorBody.h:torch::autograd::impl::set_pyobj(at::Tensor const&, _object*)
    -200  build/aten/src/ATen/core/TensorBody.h:at::detail::empty_cpu(c10::ArrayRef<long>, c10::option ... ::Layout>, c10::optional<c10::Device>, c10::optional<bool>, c10::optional<c10::MemoryFormat>)
    -200  build/../torch/csrc/utils/cuda_lazy_init.h:torch::autograd::THPVariable_empty(_object*, _object*, _object*)
    -200  /usr/include/c++/8/bits/atomic_base.h:THPVariable_clear(THPVariable*)
   -1600  build/../torch/csrc/utils/object_ptr.h:torch::FunctionSignature::parse(_object*, _object*, _object*, _object**, bool)

Total: 75497
```

## Environment

 - PyTorch Version (e.g., 1.0): Nightly. (See commits above.)
 - OS (e.g., Linux): CentOS 8
 - How you installed PyTorch (`conda`, `pip`, source): Built from source
 - Build command you used (if compiling from source): Script provided above
 - Python version: 3.7
 - CUDA/cuDNN version: N/A
 - GPU models and configuration: N/A
 - Any other relevant information: N/A

## Additional context

This is a bootcamp task. If you have any questions, please reach out to @robieta or @orionr 
CC @bitfort, @xuzhao9, @peterbell10 


cc @VitalyFedyunin @ngimel