Eliminate unnecessary copying

Description

In the FileAuditLog::flush_inlock method, we copy a string from inside _membuf into a separate object data, and, on the next source code line, destroy the original sting, which sits inside _membuf.
That unnecessary copying can be eliminated in v7.0 and v8.0 because C++20 now has stream API that supports moving.

Acceptance criteria

  • Performance not degraded - memory consumption-optimized

Environment

None

Activity

Paweł Lebioda March 19, 2025 at 9:51 AM

The solution utilizes the rvalue-qualified overload of ostringstream::str() &&, which allows returning a move-constructed string from the underlying basic_stringbuf. This approach ensures the buffer is efficiently moved and cleared after extracting the string, avoiding the need to manually reset the buffer.

However, two issues were identified:

  1. The rvalue-qualified overload is not available in LLVM's standard library before version 17.

  2. In LLVM version 17, the overload introduces an extra allocation, which negates the efficiency benefits. This issue is resolved in LLVM version 18, where the move operation is optimized correctly.

To guarantee that the buffer is cleared without requiring explicit call, the presence of a proper rvalue-qualified overload must be ensured. For this reason, a custom test has been added to SConstruct to detect the availability of the rvalue-qualified overload in the standard library used during the build.

Details

Assignee

Reporter

Needs Review

Yes

Needs QA

Yes

Needs Doc

Yes

Components

Fix versions

Priority

Smart Checklist

Created December 5, 2024 at 7:53 AM
Updated March 27, 2025 at 1:24 PM

Flag notifications