This project provides a small example of using multiple dispatch in Python via the plum library.
cd $REPO
virtualenv fooenv
source fooenv/bin/activate
pip install --editable .
pytest .
$ pytest --durations=10 .
============================= test session starts ==============================
platform linux -- Python 3.10.6, pytest-7.4.0, pluggy-1.2.0
rootdir: /home/ggoretkin/repos/investigate-plum-performance
collected 8 items
test/test_foo.py .x.. [ 50%]
test/test_zoo.py .... [100%]
============================= slowest 10 durations =============================
0.15s call test/test_zoo.py::test_workload_functional_equivalence
0.12s call test/test_zoo.py::test_perf_multiple_dispatch
0.03s call test/test_zoo.py::test_perf_elif_chain
(7 durations < 0.005s hidden. Use -vv to show these durations.)
========================= 7 passed, 1 xfailed in 0.34s =========================
python -m cProfile -o mult-disp.prof ./test/profile_zoo.py
snakeviz mult-disp.prof
or
py-spy record -o profile.svg -- python test/profile_zoo.py
reveal that plum's is_type
is the culprit.
It is being called with plum.parametric.Val[example_py_multiple_dispatch.zoo.ROS_Pose]()
and always returns false
.
See beartype/plum#86