Repository navigation
Conversation
… copies Every Transaction built TransactionAnchoredVariables, whose ~80 AnchoredVariable / AnchoredSetVariable members each copied their name into a std::string. Most names are longer than the small-string buffer, so each Transaction paid dozens of heap allocations (and frees) for names that never change. The names now live once, as static constants in the new headers/modsecurity/variable_names.h, and AnchoredVariable / AnchoredSetVariable keep a const reference to theirs. Both delete the constructor taking std::string&&, so a string literal (which would bind to a temporary and dangle) is a compile error; MULTIPART_DUPLICATE_PART_HEADER, MULTIPART_FILENAME_CHARSET and MULTIPART_FILENAME_LANGUAGE get constants. This changes the C++ API/ABI of AnchoredVariable, AnchoredSetVariable and Transaction (member types and layout). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K6LVc4WrRHJUqiUKmMqSEJ
Every AnchoredVariable embeds a VariableValue (m_var), which copied the variable's name twice more, into m_key and m_keyWithCollection. VariableValue gets a constructor tagged BorrowKey that keeps a pointer to the key instead of copying it; getKey() and getKeyWithCollection() return the borrowed key when there is one, and copies of the value borrow it too. AnchoredVariable uses it with its name, a static variable_names:: constant that outlives every value and copy. This changes the C++ API/ABI of VariableValue (a new member). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K6LVc4WrRHJUqiUKmMqSEJ
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
namespace modsecurity::variable_names { ... } (C++17) instead of two
nested blocks, as SonarCloud suggests, and one column for the constants.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K6LVc4WrRHJUqiUKmMqSEJ
|



Every
Transactionbuilds ~80 anchored variables, and each copied its name intostd::strings: once inAnchoredVariable/AnchoredSetVariable, and twice more in theVariableValueanAnchoredVariableembeds (m_key,m_keyWithCollection). Most names are longer than the small-string buffer, so creating and destroying aTransactionpaid well over a hundred heap allocations for names that never change.headers/modsecurity/variable_names.h.AnchoredVariableandAnchoredSetVariablekeep a const reference to theirs. Both delete thestd::string&&constructor, so a string literal (which would dangle) is a compile error, as suggested in the review of Perf/rule remove lookup #3615. The three variables added in 3.0.17 get constants.VariableValuegets a constructor taggedBorrowKeythat keeps a pointer to the key instead of copying it;getKey()/getKeyWithCollection()return it, and copies borrow it too.AnchoredVariableuses it with its name.Creating and destroying a
Transaction(C API, small rule set,-O2, glibc, single thread), this branch againstv3/master(44d0938):The gain is in transaction setup and teardown. With a full CRS rule set, rule evaluation dominates a request, so
test/benchmarkshows little difference; it matters where setup is a large share of the work (high request rates, small rule sets, requests that end early).This changes the C++ API/ABI of
AnchoredVariable,AnchoredSetVariable,VariableValueandTransaction.Tests: the regression suite passes (730 run, 0 failed), also under AddressSanitizer. Split out of #3615 as requested there.
Summary by CodeRabbit