From de614f952269b752d075651b24985688eb8fa369 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/Logger.hpp b/src/Utils/Logger.hpp index aac420cfc..29a29e204 100644 --- a/src/Utils/Logger.hpp +++ b/src/Utils/Logger.hpp @@ -90,7 +90,7 @@ class Logger { std::stringstream strm; strm << log_lvl << ": "; (strm << ... << std::forward(args)) << '\n'; - std::string str = strm.str(); + std::string str = std::move(strm).str(); ssize_t rc = write(fd, std::data(str), std::size(str)); (void)rc; } From 0d27189c9e134af88346ed69fb24c4337642acf9 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 | 3 +-- src/Utils/Mempool.hpp | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Buffer/Buffer.hpp b/src/Buffer/Buffer.hpp index 8200c3a98..b8185b1c4 100644 --- a/src/Buffer/Buffer.hpp +++ b/src/Buffer/Buffer.hpp @@ -276,8 +276,7 @@ class Buffer { Buffer& operator = (const Buffer& buf) = delete; Buffer(Buffer &&other) noexcept { - /* Call move assignment operator. */ - *this = std::forward(other); + *this = std::move(other); } Buffer &operator=(Buffer &&other) noexcept { diff --git a/src/Utils/Mempool.hpp b/src/Utils/Mempool.hpp index 0ef49773a..f40e17f11 100644 --- a/src/Utils/Mempool.hpp +++ b/src/Utils/Mempool.hpp @@ -48,8 +48,7 @@ class MempoolStats { MempoolStats() = default; MempoolStats(MempoolStats &&other) noexcept { - /* Call move assignment operator. */ - *this = std::forward(other); + *this = std::move(other); } MempoolStats &operator=(MempoolStats &&other) noexcept { @@ -136,15 +135,14 @@ class MempoolInstance : public MempoolStats { MempoolInstance &operator=(const MempoolInstance &other) = delete; MempoolInstance(MempoolInstance &&other) noexcept { - /* Call move assignment operator. */ - *this = std::forward(other); + *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 0401fe1591ecf126cf83d99e096b189bfe5c126f 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 +#include #include "IprotoConstants.hpp" #include "ResponseReader.hpp" @@ -85,12 +86,12 @@ class RequestEncoder { uint32_t limit = UINT32_MAX, uint32_t offset = 0, IteratorType iterator = EQ); template - size_t encodeExecute(const std::string& statement, const T& parameters); + size_t encodeExecute(std::string_view statement, const T& parameters); template size_t encodeExecute(unsigned int stmt_id, const T& parameters); - size_t encodePrepare(const std::string& statement); + size_t encodePrepare(std::string_view statement); template - size_t encodeCall(const std::string &func, const T &args); + size_t encodeCall(std::string_view func, const T &args); size_t encodeAuth(std::string_view user, std::string_view passwd, const Greeting &greet); void reencodeAuth(std::string_view user, std::string_view passwd, @@ -256,7 +257,7 @@ RequestEncoder::encodeSelect(const T &key, template template size_t -RequestEncoder::encodeExecute(const std::string& statement, const T& parameters) +RequestEncoder::encodeExecute(std::string_view statement, const T& parameters) { iterator_t request_start = m_Buf.end(); m_Buf.write('\xce'); @@ -293,7 +294,7 @@ RequestEncoder::encodeExecute(unsigned int stmt_id, const T& parameters) template size_t -RequestEncoder::encodePrepare(const std::string& statement) +RequestEncoder::encodePrepare(std::string_view statement) { iterator_t request_start = m_Buf.end(); m_Buf.write('\xce'); @@ -310,7 +311,7 @@ RequestEncoder::encodePrepare(const std::string& statement) template template size_t -RequestEncoder::encodeCall(const std::string &func, const T &args) +RequestEncoder::encodeCall(std::string_view func, const T &args) { iterator_t request_start = m_Buf.end(); m_Buf.write('\xce');