Skip to content

Commit 05ac21a

Browse files
victor-istominSergiusTheBest
authored andcommitted
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.
1 parent 1d1a101 commit 05ac21a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

include/plog/Appenders/RollingFileAppender.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ namespace plog
3535

3636
virtual void write(const Record& record) PLOG_OVERRIDE
3737
{
38+
const std::string& line = Converter::convert(Formatter::format(record));
39+
3840
util::MutexLock lock(m_mutex);
3941

4042
if (m_firstWrite)
@@ -47,7 +49,7 @@ namespace plog
4749
rollLogFiles();
4850
}
4951

50-
size_t bytesWritten = m_file.write(Converter::convert(Formatter::format(record)));
52+
size_t bytesWritten = m_file.write(line);
5153

5254
if (static_cast<size_t>(-1) != bytesWritten)
5355
{

0 commit comments

Comments
 (0)