Opens in a new tab

2026 DevOps Dozen Finalist | DevOps Open Source Project of the Year 🏆

DevOps Dozen 2026 Finalist 🏆

Vote for SKUDONET
Technical

ModSecurity Performance: Ten Patches, Five Pull Requests and the Numbers Behind Them

02/12/2026
·
LinkedIn
ModSecurity Performance
In this article

SKUDONET’s load balancer ran fast on its own, but turning on the WAF slowed it down considerably. Our engineers traced the cost to ModSecurity itself, the open-source engine behind many web application firewalls. Together with a move to PCRE2 JIT, the fixes nearly doubled throughput in our tests, and the patches are now with the ModSecurity project. 

SKUDONET’s load balancer is fast on its own. Turn on the web application firewall, though, and throughput drops considerably. That gap is what this project set out to close.

The cost comes from the WAF engine. ModSecurity is an open-source engine that checks every HTTP request against a set of rules before it reaches the application. SKUDONET’s WAF pairs libmodsecurity v3 with the OWASP Core Rule Set (CRS), a general-purpose collection of detection rules. The more rules, the more regular expressions and string operations per request, and under high traffic the CPU becomes the limit. With CRS at its strictest setting, four virtual CPUs ran at 100% while inspecting fewer than 1,700 requests per second.

The usual answers are more hardware or fewer rules. We looked for a third: finding out how much of that CPU time the engine itself was spending on work that has nothing to do with detection.

Where the CPU time went

CRS has four paranoia levels, and the fourth, PL4, is the strictest. Each request triggers hundreds of complex regular expression evaluations, string transformations and variable lookups, which makes it a good stress test. We ran it on Debian 12 with 4 vCPUs, with the WAF integrated through Pound, SKUDONET’s proxy, and generated load with wrk (two threads, 20 connections, 20 seconds, three consecutive runs per configuration). Alongside CRS, we used a synthetic scenario of 500 simple regex rules on POST arguments, with no state tracking, tags or collections, to separate the regex engine from the rest of ModSecurity.

Our starting point was ModSecurity 3.0.12, the version in SKUDONET 10.4.0. Profiling the saturated CPU showed that much of it went on housekeeping: heap allocations, temporary copies of strings and collisions in the engine’s in-memory collections.

The first gain came from the regex engine

Before touching any code, we moved to libmodsecurity 3.0.17 compiled against PCRE2 with JIT enabled, which translates regular expressions into machine code at runtime instead of interpreting them. That alone took PL4 from 1,689 to 2,074 requests per second (+22.81%) and the synthetic test from 10,280 to 13,557 (+31.88%). We count that gain apart from our patches, because it comes from the library and not from our work.

Ten patches, five pull requests

Even with JIT, the CPU was still tied up in ModSecurity’s internal state management. We wrote ten patches aimed at those hot spots and organized them in five pull requests. Each gain below was measured at CRS PL4 against the current upstream master, one pull request at a time.

Stop copying payloads (PR #3761). This was the biggest single gain, +19.76% in throughput and −16.74% in latency. When a rule chains transformations such as t:urlDecodeUni,t:lowercase, the engine used to copy the whole payload at every step, even for large POST bodies. With std::move, the data changes hands without being duplicated. The same pull request checks targets before looking up tags, caches target names and trims strings in place.

A better hash (PR #3762). ModSecurity’s in-memory collections used a hash that simply added up character values, so variables with similar names ended up in the same buckets. We replaced it with a 64-bit FNV-1a hash, removed temporary string allocations from lookups and moved the key exclusion check ahead of the mutex lock to reduce contention. Gain: +4.85%.

Tag comparisons without allocations (PR #3763). containsTag() and containsMsg() created a temporary string every time they were called. They now compare memory segments directly. The pull request comes with six new regression tests. Gain: +4.90%.

Reusing PCRE2 match data (PR #3764). Every regular expression evaluation created and freed its own match data structure, which at PL4 means thousands of allocations per request. A single thread-local block is now reused, and the match context is only allocated when a match limit is set. The gain was +2.54%. It is also the patch that touches the core of the matching path, so it is the one that will get the closest review.

Work nobody needed (PR #3760). The engine formatted debug and rule messages even when the configured log level would discard them. This pull request defers that work, reduces allocations in toHexIfNeeded() and checks rule exclusions before evaluating the operator.

What the benchmark shows

ModSecurity benchmark: 1,689 req/s on 3.0.12, 2,074 req/s with PCRE2 JIT and 3,246 req/s with SKUDONET patches under OWASP CRS at Paranoia Level 4

With JIT in place, the patches added about 56% at PL4 (from 2,074 to 3,246 requests per second) and about 12% in the synthetic scenario (from 13,557 to 15,228). Against 3.0.12, the total is +92.17% (1.92x) at PL4 and +48.13% (1.48x) in the synthetic test. The individual gains of the five pull requests don’t add up to the combined figure, since each was measured on its own.

The difference between the two scenarios is informative. The synthetic test has no state tracking, and it improves less than CRS at PL4. That fits what the patches do: they reduce allocations, copies and collection lookups, not the cost of matching regular expressions.

What it doesn’t show

Two caveats. We measured two scenarios on one hardware profile, so a heavier rule set or bigger request bodies could give a different picture. The patches go after per-request costs, and we expect those to matter more as rules and bodies grow, but we haven’t published measurements across body sizes. If you run ModSecurity, the reliable test is your own rules and your own traffic.

Same detections, same results

A faster WAF is only useful if it blocks the same things. We ran GoTestWAF, with 816 test requests across OWASP, API, community and false-positive suites and 40 concurrent workers, against the original engine and the patched one. Both blocked exactly the same malicious requests. With 128 KB payloads sent concurrently, the patched engine recorded no crashes, hangs or failed requests, and every pull request was checked with the library’s own test suite (make check).

A contribution to ModSecurity itself

We could have kept these patches inside our product. Instead, we sent the performance report and all ten patches to the ModSecurity project, as an issue on GitHub. One of the maintainers replied that performance improvements are welcome, especially at CRS PL4, where many users run into CPU limits, and confirmed that the patches apply cleanly to the current development branch. They asked for them as pull requests, so we submitted the five described above, each with its own benchmark and tests. They’re open for review now.

The value goes beyond SKUDONET. ModSecurity 3 is the engine underneath many firewalls, and a lower cost per request helps anyone running it with a demanding rule set, without changing a single rule. If the project accepts the pull requests, the improvement reaches every user of the engine, not only ours. The issue, the measurements and the code are public: https://github.com/owasp-modsecurity/ModSecurity/issues/3758

What it means for SKUDONET

These changes ship in SKUDONET Enterprise Edition 10.4.1. You can read about the rest of the release in our SKUDONET Enterprise Edition 10.4.1 announcement, and you can request an evaluation to measure them on your own traffic. 

FAQ

What is ModSecurity?

ModSecurity is an open-source web application firewall engine that checks HTTP requests against a set of rules and blocks those that match known attack patterns. Version 3, libmodsecurity, is the one SKUDONET uses, typically with the OWASP Core Rule Set.

What is PCRE2 JIT?

PCRE2 is a regular expression library, and JIT (just-in-time) compilation translates each expression into machine code at runtime instead of interpreting it. In our tests, turning it on raised ModSecurity’s throughput by 22.81% under CRS at Paranoia Level 4.

What is the ModSecurity paranoia level and why does it affect performance?

The paranoia level is a setting of the OWASP Core Rule Set, from 1 to 4, that controls how many rules are enabled. At level 4, the strictest, each request is checked against hundreds of complex regular expressions and transformations, so the CPU cost per request is much higher than at lower levels.

Does optimizing a WAF reduce its protection?

Not if the detection logic is left alone. Our patches reduce allocations, copies and lookups without changing the rules or how they are evaluated, and GoTestWAF gave identical results on the original and the patched engine.

Where can I see the patches?

In the five pull requests (#3760 to #3764) and in issue #3758 on the OWASP ModSecurity repository on GitHub, with the performance report and the per-pull-request measurements.

Subscribe to the SKUDONET newsletter
New articles and releases by email.
Explore SKUDONET Enterprise Edition
→ Start your 30-day free trial

More from Technical

Download Skudonet ADC Load Balancer
Community Edition

Source Code

A versatile and installable ADC system designed for diverse vendor hardware.

DOWNLOAD SOURCE

Installable ISO 

Load Balancing as a Service alongside an ADC orchestration toolkit.

DOWNLOAD ISO