pycasbin
pycasbin copied to clipboard
[PyCasbin-on-CPP] Benchmark the slow part of PyCasbin as the preparation for PyCasbin-on-CPP
There are many users complaining PyCasbin about its bad performance compared to Go or Java. This is mostly because that PyCasbin is a pure Python implementation of Casbin. A common practice for popular Python libs for this is using a C++ backend and wrapping it with a Python interface, like numpy, tensorflow, pytorch. We can do similar and this plan is named "PyCasbin-on-CPP".
Recently the Casbin-CPP is already usable and some preparation work for PyCasbin-on-CPP is done: https://github.com/casbin/casbin-cpp/issues/84 . The next question is which parts of the Python code and how much of them should be replaced by C++ code, only the evaluator code, or the enforce function, or even includes some other APIs.
We need to use some profiling tool to recognize the slow parts of PyCasbin. Then we replace them with C++ first ideally.
@ffyuanda @Zxilly @techoner @elfisworking
@sheny1xuan will work on the Casbin-CPP part.
@Abingcbc will work on the PyCasbin part.
Please work together.
If pycasbin-on-cpp
is a standalone lib, should we replace all the APIs of PyCasbin with C++ or still replace the slow parts with C++?
BTW, should we write an RFC first like the one of TensorFlow https://github.com/tensorflow/community/blob/master/rfcs/20190208-pybind11.md @hsluoyz
@Abingcbc good point!
Today, it is also more an more common to bind Python over Rust instead of C/C++. Casbin have a Rust implementation (marked as "Producton ready"). This can achieve the same performance gain, but also bring the Rust security benefits.
See: https://github.com/PyO3/PyO3
Today, it is also more an more common to bind Python over Rust instead of C/C++. Casbin have a Rust implementation (marked as "Producton ready"). This can achieve the same performance gain, but also bring the Rust security benefits.
See: https://github.com/PyO3/PyO3
@leeqvip @Abingcbc @EmperorYP7 @sheny1xuan any comment on this?
- I think C++ still has an edge due to the deeper integration capabilities with CPython than that of Rust's.
pybind-11
leverages the C API in Python to get close to the native level performance of C++ while being accessible in Python code. - I believe that
pybind-11
is more mature thanPyO3
and has better developer support and community. (its just my opinion, not a fact) -
pybind
is not obsolete by today's standards. It's still being used by software like Tensorflow. - Building rust binding would have been feasible if Casbin had been a Rust-first software. Since, we've made a language binding already, I believe pycasbin-on-cpp is great for now.
How i can contribute on this issuse
I'm curious if there's been any progress in implementing pycasbin-on-cpp or if this issue is basically stalled?
@EmperorYP7 @sheny1xuan what's the current status for pycasbin-on-cpp?
The experiment shows that PyCasbin-on-CPP is not much faster than pure PyCasbin, maybe 5%~10% faster but this is not enough. Pure PyCasbin is much easier to maintain compared to the slightly faster PyCasbin-on-CPP. Closed here for now