You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2022/11/07 03:53:57 UTC

[GitHub] [logging-log4cxx] swebb2066 opened a new pull request, #148: Reduce std::ostream logging overhead

swebb2066 opened a new pull request, #148:
URL: https://github.com/apache/logging-log4cxx/pull/148

   This PR reduces the overhead of logging values through `operator<<(std::ostream&` by using a thread local std::basic_ostringstream where available.
   
   It retains the static string logging optimization,  thereby resolving the issue with the previous attempt (Thorsten Schöning 2018-08-19) to introduce this optimization.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [logging-log4cxx] swebb2066 merged pull request #148: Reduce std::ostream logging overhead

Posted by GitBox <gi...@apache.org>.
swebb2066 merged PR #148:
URL: https://github.com/apache/logging-log4cxx/pull/148


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [logging-log4cxx] rm5248 commented on a diff in pull request #148: Reduce std::ostream logging overhead

Posted by GitBox <gi...@apache.org>.
rm5248 commented on code in PR #148:
URL: https://github.com/apache/logging-log4cxx/pull/148#discussion_r1015347242


##########
src/main/cpp/messagebuffer.cpp:
##########
@@ -149,10 +118,14 @@ CharMessageBuffer& CharMessageBuffer::operator<<(const char msg)
 
 CharMessageBuffer::operator std::basic_ostream<char>& ()
 {
-	if (m_priv->stream == 0)
+	if (!m_priv->stream)
 	{
+#if LOG4CXX_HAS_THREAD_LOCAL
+		thread_local static std::basic_ostringstream<char> sStream;
+		m_priv->stream = &sStream;
+#else
 		m_priv->stream = new std::basic_ostringstream<char>();
-
+#endif

Review Comment:
   At this point I'm not aware of any compiler that supports C++11 but not `thread_local`, would it make sense to simply make `m_priv->stream` a `thread_local` variable instead of holding a pointer?  I could be wrong here, but it looks like if two threads are logging at the same time they could both get the same `ostringstream`, thus defeating the purpose of the `thread_local`. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [logging-log4cxx] swebb2066 commented on a diff in pull request #148: Reduce std::ostream logging overhead

Posted by GitBox <gi...@apache.org>.
swebb2066 commented on code in PR #148:
URL: https://github.com/apache/logging-log4cxx/pull/148#discussion_r1015945163


##########
src/main/cpp/messagebuffer.cpp:
##########
@@ -149,10 +118,14 @@ CharMessageBuffer& CharMessageBuffer::operator<<(const char msg)
 
 CharMessageBuffer::operator std::basic_ostream<char>& ()
 {
-	if (m_priv->stream == 0)
+	if (!m_priv->stream)
 	{
+#if LOG4CXX_HAS_THREAD_LOCAL
+		thread_local static std::basic_ostringstream<char> sStream;
+		m_priv->stream = &sStream;
+#else
 		m_priv->stream = new std::basic_ostringstream<char>();
-
+#endif

Review Comment:
   > would it make sense to simply make `m_priv->stream` a `thread_local `variable instead of holding a pointer
   
   The `m_priv->stream` must be zero when logging only `std::string` or `char* ` to implement the static string logging optimization.
   
   > looks like if two threads are logging at the same time they could both get the same ostringstream
   
   The `thread_local ` implementation should ensure the sSteam obtained by each thread will be different, and the `m_priv->stream` pointer life-time is the `MessageBuffer` lifetime. The only way two threads could share the same `ostringstream` is if the user provides a `MessageBuffer` object reference to the other thread. `MessageBuffer` is not intended to be used outside LOG4CXX_* macros.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org