Closed ailiujiarui closed 2 months ago
@EmperorYP7 @sheny1xuan @cs1137195420 please review
Hi @fishsclue, can you test this PR?
:tada: This PR is included in version 1.57.0 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
Fix: https://github.com/casbin/casbin-cpp/issues/243
Description
When the enforce function is called 10,000 times, the memory stays at 3MB for a while before it linearly increases to around 40MB. Using the performance analysis tool built into VS2022, snapshots were taken during the program’s runtime to compare the differences in memory and call counts. Clicking on the snapshot allows you to see which functions were called in the stack and what objects exist. After repeated comparisons, it was found that after the number of calls to GetExprtkFunction increased, many smart pointer objects were created and not released in time, causing the memory to continue to rise. I modified the function’s running logic, using an object pool to store the required objects and returning objects as needed. After completion, the memory occupied by the same number of calls dropped to 4~5MB.
Screenshots/Testimonials
before:![image](https://github.com/casbin/casbin-cpp/assets/115072567/fcbcf823-f643-472d-9f75-2750c474bb70)
now:![image](https://github.com/casbin/casbin-cpp/assets/115072567/53a336d9-220a-48d4-8174-31d6212e4e8b)