pycasbin icon indicating copy to clipboard operation
pycasbin copied to clipboard

[PyCasbin-on-CPP] Benchmark the slow part of PyCasbin as the preparation for PyCasbin-on-CPP

Open hsluoyz opened this issue 2 years ago • 11 comments

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.

hsluoyz avatar Nov 25 '21 15:11 hsluoyz

@ffyuanda @Zxilly @techoner @elfisworking

casbin-bot avatar Nov 25 '21 15:11 casbin-bot

@sheny1xuan will work on the Casbin-CPP part.

@Abingcbc will work on the PyCasbin part.

Please work together.

hsluoyz avatar Nov 27 '21 12:11 hsluoyz

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++?

Abingcbc avatar Nov 28 '21 05:11 Abingcbc

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 avatar Nov 28 '21 06:11 Abingcbc

@Abingcbc good point!

hsluoyz avatar Dec 09 '21 16:12 hsluoyz

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

JGoutin avatar Jan 28 '22 15:01 JGoutin

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?

hsluoyz avatar Jan 28 '22 16:01 hsluoyz

  • 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 than PyO3 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.

EmperorYP7 avatar Jan 29 '22 19:01 EmperorYP7

How i can contribute on this issuse

SidharajYadav avatar Feb 07 '22 04:02 SidharajYadav

I'm curious if there's been any progress in implementing pycasbin-on-cpp or if this issue is basically stalled?

pacificsky avatar May 10 '22 04:05 pacificsky

@EmperorYP7 @sheny1xuan what's the current status for pycasbin-on-cpp?

hsluoyz avatar May 10 '22 05:05 hsluoyz

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

hsluoyz avatar Nov 23 '22 14:11 hsluoyz