-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Use std::shared_ptr for variable resolution #2374
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
Use std::shared_ptr for variable resolution #2374
Conversation
IMPORTANT: SecDefaultAction specified on a child configuration will overwrite the ones specified on the parent; Previously it was concatenating.
@WGH- do you mind to test it again against the top of v3.1-experimental. If it still failing, can you share the set of rules that you are using? I am not able to reproduce it here. |
I'm having the same crash in my benchmark in base v3.1-experimental. I suppose this patch is not at fault, it just shuffled something a bit so the underlying problem surfaces in the regression test. I'll create a minimal reproduction, and report back to #2376 |
b321829
to
5a243f3
Compare
It seems that push_back was used together with std::make_shared on different places, those could be replaced with emplace_back. I am having it tested here. |
|
7d07aa6
to
8853877
Compare
cb599d6
to
b185ae4
Compare
7caf18c
to
baf1899
Compare
4e6f485
to
b4a8fa9
Compare
33752b3
to
abf59f4
Compare
@zimmerle Did you already merge it into v3/dev/3.1-experimental? Or what happened? |
Yes. It is merged on v3.1-experimental. As shared pointer I have delayed the variable resolution to the next minute if needed. I did not collected the numbers yet, trying to make the branch stable first. Other change that I did, was this: cc5d3f5 |
I am going to close this. We can track the performance numbers in a separated issue, if needed. Thank you @WGH- . |
It's just the state of this PR after you force-pushed some diverged branch utterly confused me. It's clear now, thanks, |
v3.1-experimental is being rebased against v3/master from time to time, indeed it is confusing. |
AnchoredSetVariable::resolve
is called for every rule (seeRuleWithOperator::evaluate
). The previous implementation allocated a new copy of every variable, which quickly added up. In my tests,AnchoredSetVariable::resolve
function consumed 7.8% of run time.AnchoredSetVariable
(which is a multimap) values are never changed, only added. This means it's safe to store them instd::shared_ptr
, and makeresolve
returnshared_ptr
pointing to the same object.Other resolve implementation could also use this optimization by not allocating new objects, however, they are not hot spots, so this optimization was not implemented there.
In my benchmark, this raises performance from 117 requests per second to 131 RPS, and overhead is lowered from 7.8% to 2.4%.
As a bonus, replacing plain pointer with smart pointers make code cleaner, since using smart pointers makes manual deletes no longer necessary.
Additionally,
VariableOrigin
is now stored in plainstd::vector
, since it's wasteful to store structure containing just two integer values usingstd::list<std::unique_ptr<T>>
.Before (the thing to the left of


executeTransformations
labeled "modsecuri.."):After:
SVG files for the flamegraphs: flamegraphs.tar.gz