Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
hsluoyz opened this issue Nov 25, 2021 · 12 comments
Assignees
Labels
enhancement New feature or request

Comments

@hsluoyz
Copy link
Member

hsluoyz commented Nov 25, 2021

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: casbin/casbin-cpp#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.

@casbin-bot
Copy link
Member

@ffyuanda @Zxilly @techoner @elfisworking

@casbin-bot casbin-bot added the question Further information is requested label Nov 25, 2021
@hsluoyz hsluoyz changed the title Benchmark the slow part of PyCasbin as the preparation for PyCasbin-on-CPP [PyCasbin-on-CPP] Benchmark the slow part of PyCasbin as the preparation for PyCasbin-on-CPP Nov 25, 2021
@hsluoyz hsluoyz added enhancement New feature or request and removed question Further information is requested labels Nov 27, 2021
@hsluoyz
Copy link
Member Author

hsluoyz commented Nov 27, 2021

@sheny1xuan will work on the Casbin-CPP part.

@Abingcbc will work on the PyCasbin part.

Please work together.

@Abingcbc
Copy link
Member

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
Copy link
Member

BTW, should we write an RFC first like the one of TensorFlow https://github.com/tensorflow/community/blob/master/rfcs/20190208-pybind11.md
@hsluoyz

@hsluoyz
Copy link
Member Author

hsluoyz commented Dec 9, 2021

@Abingcbc good point!

@JGoutin
Copy link

JGoutin commented Jan 28, 2022

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

@hsluoyz
Copy link
Member Author

hsluoyz commented Jan 28, 2022

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?

@EmperorYP7
Copy link
Member

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

@SidharajYadav
Copy link

How i can contribute on this issuse

@pacificsky
Copy link

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

@hsluoyz
Copy link
Member Author

hsluoyz commented May 10, 2022

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

@hsluoyz
Copy link
Member Author

hsluoyz commented Nov 23, 2022

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 hsluoyz closed this as completed Nov 23, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants