From 05ac21a33bf32bbbf5370e0f9aa9245643385cb1 Mon Sep 17 00:00:00 2001 From: Victor Istomin Date: Sun, 20 Aug 2023 11:30:58 +0300 Subject: [PATCH] Improve multithreaded performance (#1) Mutex lock is not necessary when performing line formatting and conversion to UTF-8, so I have moved string manipulation out of the locked scope. This gave more concurrency level and about 3 times more performance on Windows with my test sample. --- include/plog/Appenders/RollingFileAppender.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/plog/Appenders/RollingFileAppender.h b/include/plog/Appenders/RollingFileAppender.h index 3b66728..5d1a6ed 100644 --- a/include/plog/Appenders/RollingFileAppender.h +++ b/include/plog/Appenders/RollingFileAppender.h @@ -35,6 +35,8 @@ namespace plog virtual void write(const Record& record) PLOG_OVERRIDE { + const std::string& line = Converter::convert(Formatter::format(record)); + util::MutexLock lock(m_mutex); if (m_firstWrite) @@ -47,7 +49,7 @@ namespace plog rollLogFiles(); } - size_t bytesWritten = m_file.write(Converter::convert(Formatter::format(record))); + size_t bytesWritten = m_file.write(line); if (static_cast(-1) != bytesWritten) {