corazawaf / coraza

OWASP Coraza WAF is a golang modsecurity compatible web application firewall library
https://www.coraza.io
Apache License 2.0
2.28k stars 226 forks source link

perf: reduces transformArg allocation without multimatch #1198

Closed M4tteoP closed 1 week ago

M4tteoP commented 2 weeks ago

Avoids allocations when calling transformArg() without Multimatch. This has been done by specializing the transformArg into:

Before:

goos: darwin
goarch: arm64
pkg: github.com/corazawaf/coraza/v3/testing/coreruleset
cpu: Apple M1 Pro
BenchmarkCRSSimplePOST-10            901       1256223 ns/op      320564 B/op       6420 allocs/op
PASS
ok      github.com/corazawaf/coraza/v3/testing/coreruleset  2.051s

After:

BenchmarkCRSSimplePOST-10            902       1252754 ns/op      309035 B/op       5657 allocs/op
PASS
ok      github.com/corazawaf/coraza/v3/testing/coreruleset  2.053s
codecov[bot] commented 1 week ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 81.64%. Comparing base (12d554b) to head (135eddb). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1198 +/- ## ========================================== + Coverage 81.63% 81.64% +0.01% ========================================== Files 168 168 Lines 9630 9637 +7 ========================================== + Hits 7861 7868 +7 Misses 1519 1519 Partials 250 250 ``` | [Flag](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | Coverage Δ | | |---|---|---| | [coraza.rule.case_sensitive_args_keys](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | `81.60% <100.00%> (+0.01%)` | :arrow_up: | | [coraza.rule.multiphase_valuation](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | `81.64% <100.00%> (+0.01%)` | :arrow_up: | | [default](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | `81.64% <100.00%> (+0.01%)` | :arrow_up: | | [examples+](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | `16.43% <25.58%> (+0.04%)` | :arrow_up: | | [examples+coraza.rule.case_sensitive_args_keys](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | `81.60% <100.00%> (+0.01%)` | :arrow_up: | | [examples+coraza.rule.multiphase_valuation](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | `81.52% <100.00%> (+0.01%)` | :arrow_up: | | [examples+memoize_builders](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | `81.65% <100.00%> (+0.01%)` | :arrow_up: | | [examples+no_fs_access](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | `80.96% <100.00%> (+0.01%)` | :arrow_up: | | [ftw](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | `81.64% <100.00%> (+0.01%)` | :arrow_up: | | [memoize_builders](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | `81.73% <100.00%> (+0.01%)` | :arrow_up: | | [no_fs_access](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | `81.08% <100.00%> (+0.01%)` | :arrow_up: | | [tinygo](https://app.codecov.io/gh/corazawaf/coraza/pull/1198/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf) | `81.61% <100.00%> (+0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=corazawaf#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.