Keyword argument handling performance optimization.
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Issue description
Keyword argument handling is slower than CPython.
CPython has an optimization that assumes the keyword name string objects are interned and performs pointer comparisons first instead https://github.com/python/cpython/blob/22424c02e51fab3b62cbe255d0b87d1b55b9a6c3/Python/ceval.c#L3975 .
Whereas Pybind constructs string objects and hashes them https://github.com/pybind/pybind11/blob/fb910ae92b4a489e9b31f9ec545bde9d09d6a40e/include/pybind11/pybind11.h#L518 .
What do you think about having a similar optimization in Pybind?
Reproducible example code
void matmul(py::handle a,
py::handle b,
py::handle transpose_a,
py::handle transpose_b,
py::handle adjoint_a,
py::handle adjoint_b,
py::handle a_is_sparse,
py::handle b_is_sparse,
py::handle name) {
}
PYBIND11_MODULE(test, m) {
m.def("matmul", &matmul,
py::arg("a"),
py::arg("b"),
py::arg("transpose_a") = false,
py::arg("transpose_b") = false,
py::arg("adjoint_a") = false,
py::arg("adjoint_b") = false,
py::arg("a_is_sparse") = false,
py::arg("b_is_sparse") = false,
py::arg("name") = "");
}
test.matmul(1, 2, transpose_a = True)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the keyword-argument handling around include/pybind11/pybind11.h#L518 and compare it with the linked CPython ceval.c optimization. Run the reproducible matmul example to establish the current behavior and performance; done means the proposed interned-name or pointer-comparison optimization is implemented and its effect is verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100