Skip to content

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

Merged
hsluoyz merged 1 commit into
apache:masterfrom
cbaecker:perf/built-in-functions
Oct 3, 2024
Merged

hsluoyz merged 1 commit into
apache:masterfrom
cbaecker:perf/built-in-functions

Conversation

@cbaecker

@cbaecker cbaecker commented Oct 2, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown

@EmperorYP7 @sheny1xuan @cs1137195420 please review

@CLAassistant

CLAassistant commented Oct 2, 2024 •

Copy link
Copy Markdown

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 apache:master Oct 3, 2024
@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