perf: use small::vector<> when sorting map keys (#7928)

I collected stats for a full day & found N=32 to be enough for 99% of cases
This commit is contained in:
Charles Kerr
2025-12-13 14:45:43 -06:00
committed by GitHub
parent 0fcda4e977
commit 98fdf2dc0b
2 changed files with 8 additions and 2 deletions

View File

@@ -18,6 +18,8 @@
#include <fmt/compile.h>
#include <fmt/format.h>
#include <small/vector.hpp>
#define LIBTRANSMISSION_VARIANT_MODULE
#include "libtransmission/benc.h"
@@ -279,7 +281,8 @@ using OutBuf = fmt::memory_buffer;
[[nodiscard]] auto sorted_entries(tr_variant::Map const& map)
{
auto entries = std::vector<std::pair<std::string_view, tr_variant const*>>{};
static auto constexpr N = 32U;
auto entries = small::vector<std::pair<std::string_view, tr_variant const*>, N>{};
entries.reserve(map.size());
for (auto const& [key, child] : map)
{

View File

@@ -19,6 +19,8 @@
#include <fmt/format.h>
#include <small/vector.hpp>
#include <rapidjson/encodedstream.h>
#include <rapidjson/encodings.h>
#include <rapidjson/error/en.h>
@@ -294,7 +296,8 @@ private:
[[nodiscard]] auto sorted_entries(tr_variant::Map const& map)
{
auto entries = std::vector<std::pair<std::string_view, tr_variant const*>>{};
static auto constexpr N = 32U;
auto entries = small::vector<std::pair<std::string_view, tr_variant const*>, N>{};
entries.reserve(map.size());
for (auto const& [key, child] : map)
{