Skip to content

Commit

Permalink
Improve multithreaded performance (#1)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
victor-istomin authored and SergiusTheBest committed Aug 20, 2023
1 parent 1d1a101 commit 05ac21a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/plog/Appenders/RollingFileAppender.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<size_t>(-1) != bytesWritten)
{
Expand Down

0 comments on commit 05ac21a

Please sign in to comment.