Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Improve performance of built-in-functions via static regexes #249

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

cbaecker
Copy link
Contributor

@cbaecker cbaecker commented Oct 2, 2024

Description

Instantiation of std::regex involves parsing and compiling the regular expression and should therefore be considered "expensive".

In this PR I changed some constant std::regex in the built-in-functions to static variables and moved those that are used multiple times to an anonymous namespace. I also introduced a few functions to reduce code duplication.

In the specific use case, this was tested with 1000 different requests. These were structured in such a way that the entire policy had to be run through each time.
The time saving was around 40%.
casbintest runs about 25% faster.

I tried to reflect functionality of the regex-expressions in the variable-names.

Testimonials

Unmodified version:

$ time ./casbintest >/dev/null

real    0m2.333s
user    0m1.968s
sys     0m0.230s

With this change:

$ time ./casbintest >/dev/null

real    0m1.733s
user    0m1.260s
sys     0m0.180s

@casbin-bot
Copy link
Member

@EmperorYP7 @sheny1xuan @cs1137195420 please review

@CLAassistant
Copy link

CLAassistant commented Oct 2, 2024

CLA assistant check
All committers have signed the CLA.

@cbaecker cbaecker changed the title Improve performance of built-in-functions perf: Improve performance of built-in-functions Oct 2, 2024
@cbaecker cbaecker force-pushed the perf/built-in-functions branch from e2a49b0 to 6c17554 Compare October 2, 2024 14:17
@hsluoyz hsluoyz changed the title perf: Improve performance of built-in-functions feat: Improve performance of built-in-functions via static regexes Oct 3, 2024
@hsluoyz hsluoyz merged commit 789f3e0 into casbin:master Oct 3, 2024
13 of 14 checks passed
@cbaecker cbaecker deleted the perf/built-in-functions branch October 3, 2024 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants