From f9a7b92df99ae36cc1582b34c834e0bfba077f70 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 24 Jun 2022 15:50:10 +0200 Subject: [PATCH] dnsdist: Use unordered sets to speed things up a bit --- pdns/dnsdist-idstate.hh | 2 +- pdns/dnsdist-lua-actions.cc | 3 ++- pdns/dnsdist-lua.hh | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pdns/dnsdist-idstate.hh b/pdns/dnsdist-idstate.hh index d11c5c4226..e90bf953c2 100644 --- a/pdns/dnsdist-idstate.hh +++ b/pdns/dnsdist-idstate.hh @@ -117,7 +117,7 @@ struct InternalQueryState InternalQueryState& operator=(const InternalQueryState& orig) = delete; boost::optional subnet{boost::none}; // 40 - std::set ttlCapTypes; + std::unordered_set ttlCapTypes; ComboAddress origRemote; // 28 ComboAddress origDest; // 28 ComboAddress hopRemote; diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index af6fec942f..7e5ecb8df6 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -2329,8 +2329,9 @@ void setupLuaActions(LuaContext& luaCtx) }); luaCtx.writeFunction("LimitTTLResponseAction", [](uint32_t min, uint32_t max, boost::optional> types) { - std::set capTypes; + std::unordered_set capTypes; if (types) { + capTypes.reserve(types->size()); for (const auto& [idx, type] : *types) { capTypes.insert(QType(type)); } diff --git a/pdns/dnsdist-lua.hh b/pdns/dnsdist-lua.hh index abaf11904a..9570f3e802 100644 --- a/pdns/dnsdist-lua.hh +++ b/pdns/dnsdist-lua.hh @@ -88,7 +88,7 @@ public: private: static thread_local std::default_random_engine t_randomEngine; std::vector d_addrs; - std::set d_types; + std::unordered_set d_types; std::vector d_rawResponses; PacketBuffer d_raw; DNSName d_cname; @@ -99,7 +99,7 @@ class LimitTTLResponseAction : public DNSResponseAction, public boost::noncopyab public: LimitTTLResponseAction() {} - LimitTTLResponseAction(uint32_t min, uint32_t max = std::numeric_limits::max(), std::set types = {}) : d_types(types), d_min(min), d_max(max) + LimitTTLResponseAction(uint32_t min, uint32_t max = std::numeric_limits::max(), std::unordered_set types = {}) : d_types(types), d_min(min), d_max(max) { } @@ -146,7 +146,7 @@ public: } private: - std::set d_types; + std::unordered_set d_types; uint32_t d_min{0}; uint32_t d_max{std::numeric_limits::max()}; }; -- 2.47.2