From fbad0e854d877845c2f90fcefd3d6d00e09f9539 Mon Sep 17 00:00:00 2001
From: Pavel Melkozerov
Date: Tue, 30 Sep 2025 23:47:39 +0300
Subject: [PATCH 1/3] logger: make logger a bit faster
Eliminate copying from std::stringstream if complied with C++20 or higher
---
src/Utils/Logger.hpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/Utils/Logger.hpp b/src/Utils/Logger.hpp
index aac420cfc..59907eb39 100644
--- a/src/Utils/Logger.hpp
+++ b/src/Utils/Logger.hpp
@@ -90,7 +90,11 @@ class Logger {
std::stringstream strm;
strm << log_lvl << ": ";
(strm << ... << std::forward(args)) << '\n';
- std::string str = strm.str();
+ /*
+ * std::move is required to eliminate copying from
+ * std::stringstream if complied with C++20 or higher.
+ */
+ std::string str = std::move(strm).str();
ssize_t rc = write(fd, std::data(str), std::size(str));
(void)rc;
}
From 259269fc4d29a256d0ac172716ed805bc30108da Mon Sep 17 00:00:00 2001
From: Pavel Melkozerov
Date: Wed, 1 Oct 2025 00:37:55 +0300
Subject: [PATCH 2/3] utils: std::forward related fixes
std::forward were replace std::move for fixed type context where
it does not make sense. Some redundant comment were removed as they
declare obvious actions under them.
---
src/Buffer/Buffer.hpp | 6 +-----
src/Utils/Mempool.hpp | 14 +++-----------
2 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/src/Buffer/Buffer.hpp b/src/Buffer/Buffer.hpp
index 8200c3a98..a6b5247cd 100644
--- a/src/Buffer/Buffer.hpp
+++ b/src/Buffer/Buffer.hpp
@@ -274,11 +274,7 @@ class Buffer {
Buffer(allocator &&all = allocator());
Buffer(const Buffer& buf) = delete;
Buffer& operator = (const Buffer& buf) = delete;
- Buffer(Buffer &&other) noexcept
- {
- /* Call move assignment operator. */
- *this = std::forward(other);
- }
+ Buffer(Buffer &&other) noexcept { *this = std::move(other); }
Buffer &operator=(Buffer &&other) noexcept
{
if (this == &other)
diff --git a/src/Utils/Mempool.hpp b/src/Utils/Mempool.hpp
index 0ef49773a..9ff53eebe 100644
--- a/src/Utils/Mempool.hpp
+++ b/src/Utils/Mempool.hpp
@@ -46,11 +46,7 @@ class MempoolStats {
void statDelBlock() { --m_BlockCount; }
public:
MempoolStats() = default;
- MempoolStats(MempoolStats &&other) noexcept
- {
- /* Call move assignment operator. */
- *this = std::forward(other);
- }
+ MempoolStats(MempoolStats &&other) noexcept { *this = std::move(other); }
MempoolStats &operator=(MempoolStats &&other) noexcept
{
std::swap(m_SlabCount, other.m_SlabCount);
@@ -134,17 +130,13 @@ class MempoolInstance : public MempoolStats {
MempoolInstance() = default;
MempoolInstance(const MempoolInstance &other) = delete;
MempoolInstance &operator=(const MempoolInstance &other) = delete;
- MempoolInstance(MempoolInstance &&other) noexcept
- {
- /* Call move assignment operator. */
- *this = std::forward(other);
- }
+ MempoolInstance(MempoolInstance &&other) noexcept { *this = std::move(other); }
MempoolInstance &operator=(MempoolInstance &&other) noexcept
{
if (this == &other)
return *this;
/* Move base class. */
- MempoolStats::operator=(std::forward(other));
+ MempoolStats::operator=(std::move(other));
std::swap(m_SlabList, other.m_SlabList);
std::swap(m_FreeList, other.m_FreeList);
std::swap(m_SlabDataBeg, other.m_SlabDataBeg);
From 4fecfc2c633d7163e07f7d53e07bf5dca352dfa9 Mon Sep 17 00:00:00 2001
From: Pavel Melkozerov
Date: Wed, 1 Oct 2025 00:44:51 +0300
Subject: [PATCH 3/3] client: use std::string_view for call function
For most of cases encoding fuction such as `call`, `execute` and
`prepare` use predefined fixed literal. Those values are best to
be expressed as std::string_view literals.
std::string_view are really usefull and can be easily createad
from any sequense memory areas.
There are no changes are required from cliend side as
std::string_view can be implicilty coverted from std::string.
---
src/Client/Connection.hpp | 13 +++++++------
src/Client/RequestEncoder.hpp | 13 +++++++------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/src/Client/Connection.hpp b/src/Client/Connection.hpp
index d9626f0ba..db7b323af 100644
--- a/src/Client/Connection.hpp
+++ b/src/Client/Connection.hpp
@@ -37,6 +37,7 @@
#include //iovec
#include
+#include
#include //futures
/** rid == request id */
@@ -175,7 +176,7 @@ class Connection
size_t getFutureCount() const;
template
- rid_t call(const std::string &func, const T &args);
+ rid_t call(std::string_view func, const T &args);
rid_t ping();
/**
@@ -185,7 +186,7 @@ class Connection
* @retval request id
*/
template
- rid_t execute(const std::string& statement, const T& parameters);
+ rid_t execute(std::string_view statement, const T& parameters);
/**
* Execute the SQL statement contained in the 'statement' parameter.
@@ -203,7 +204,7 @@ class Connection
* @param statement statement, which should conform to the rules for SQL grammar
* @retval request id
*/
- rid_t prepare(const std::string& statement);
+ rid_t prepare(std::string_view statement);
void setError(const std::string &msg, int errno_ = 0);
bool hasError() const;
@@ -606,7 +607,7 @@ decodeGreeting(Connection &conn)
template
template
rid_t
-Connection::execute(const std::string& statement, const T& parameters)
+Connection::execute(std::string_view statement, const T& parameters)
{
impl->enc.encodeExecute(statement, parameters);
impl->connector.readyToSend(*this);
@@ -625,7 +626,7 @@ Connection::execute(unsigned int stmt_id, const T& paramete
template
rid_t
-Connection::prepare(const std::string& statement)
+Connection::prepare(std::string_view statement)
{
impl->enc.encodePrepare(statement);
impl->connector.readyToSend(*this);
@@ -635,7 +636,7 @@ Connection::prepare(const std::string& statement)
template
template
rid_t
-Connection::call(const std::string &func, const T &args)
+Connection::call(std::string_view func, const T &args)
{
impl->enc.encodeCall(func, args);
impl->connector.readyToSend(*this);
diff --git a/src/Client/RequestEncoder.hpp b/src/Client/RequestEncoder.hpp
index b4862615f..ae01b6ffe 100644
--- a/src/Client/RequestEncoder.hpp
+++ b/src/Client/RequestEncoder.hpp
@@ -32,6 +32,7 @@
#include
#include
#include