Skip to content

Commit 4d3ab26

Browse files
swolchokpytorchmergebot
authored andcommitted
Stop trying to intern arguments in PyObject_FastGetAttrString (pytorch#161432)
If we want them interned, we should intern at callsites. (The numpy reference has bit rotted; see numpy/numpy@b222eb6#diff-6bdb6105198083838f51c57b55b3a49472ed23043bb40018f1ea41138e687163) Profiling a simple torchdispatch benchmark with perf before/after seems to show that time spent copying std::strings and interning Python strings is gone, though there is some noise and the improvement is very small. Pull Request resolved: pytorch#161432 Approved by: https://github.com/ezyang ghstack dependencies: pytorch#161301, pytorch#161292, pytorch#161304, pytorch#161308, pytorch#161315, pytorch#161317, pytorch#161328, pytorch#161329
1 parent 0ee8a4e commit 4d3ab26

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

torch/csrc/utils/python_strings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ inline py::object PyObject_FastGetAttrString(PyObject* obj, const char* name) {
116116
}
117117
/* Attribute referenced by (PyObject *)name */
118118
else if (tp->tp_getattro != nullptr) {
119-
auto w = py::reinterpret_steal<py::object>(THPUtils_internString(name));
119+
auto w = py::reinterpret_steal<py::object>(PyUnicode_FromString(name));
120120
if (w.ptr() == nullptr) {
121121
return py::object();
122122
}

0 commit comments

Comments
 (0)