refactor: switch from folly's to boost's small_vector

This commit is contained in:
Marcus Holland-Moritz 2024-07-27 15:00:06 +02:00
parent d1919ae369
commit 960346c019
5 changed files with 56 additions and 9 deletions

View File

@ -47,7 +47,10 @@ class single_inode_fragment {
void add_chunk(size_t block, size_t offset, size_t size);
std::span<thrift::metadata::chunk const> chunks() const { return chunks_; }
std::span<thrift::metadata::chunk const> chunks() const {
// TODO: workaround for older boost small_vector
return std::span(chunks_.data(), chunks_.size());
}
void extend(file_off_t length) { length_ += length; }
@ -71,7 +74,10 @@ class inode_fragments {
return fragments_.emplace_back(category, length);
}
std::span<single_inode_fragment const> span() const { return fragments_; }
std::span<single_inode_fragment const> span() const {
// TODO: workaround for older boost small_vector
return std::span(fragments_.data(), fragments_.size());
}
single_inode_fragment const& back() const { return fragments_.back(); }
single_inode_fragment& back() { return fragments_.back(); }

View File

@ -151,7 +151,10 @@ class basic_offset_cache {
chunk_index_type first_index() const { return first_index_; }
std::span<file_offset_type const> offsets() const { return offsets_; }
std::span<file_offset_type const> offsets() const {
// TODO: workaround for older boost small_vector
return std::span(offsets_.data(), offsets_.size());
}
private:
small_vector<file_offset_type, max_inline_offsets> offsets_;

View File

@ -86,7 +86,10 @@ class performance_monitor_proxy {
~section_timer() {
if (mon_) {
mon_->add_sample(id_, start_,
context_ ? *context_ : std::span<uint64_t const>{});
context_
// TODO: workaround for older boost small_vector
? std::span{context_->data(), context_->size()}
: std::span<uint64_t const>{});
}
}

View File

@ -21,13 +21,43 @@
#pragma once
#include <folly/small_vector.h>
// #include <boost/container/small_vector.hpp>
#include <boost/container/small_vector.hpp>
namespace dwarfs {
/*
Turns out boost's small_vector is faster on average than folly's.
----------------------------------------------------------------
int string
folly boost folly boost
----------------------------------------------------------------
defaultCtor 28.90ns 13.20ns 30.53ns 14.60ns
sizeCtor(16) 205.65ns 36.78ns 289.87ns 110.44ns
sizeCtor(128) 420.11ns 38.47ns 872.85ns 598.27ns
sizeCtor(1024) 2.15us 77.12ns 4.50us 4.47us
fillCtor(16) 227.79ns 100.11ns 13.44us 13.23us
fillCtor(128) 457.34ns 387.14ns 17.44us 17.49us
fillCtor(1024) 2.33us 2.67us 46.35us 46.18us
reserve(16) 192.40ns 87.70ns 232.90ns 99.59ns
reserve(128) 191.61ns 87.51ns 248.49ns 117.94ns
reserve(1024) 230.65ns 108.48ns 266.32ns 122.62ns
insertFront(16) 3.08us 3.04us 126.98us 111.87us
insertFront(128) 3.08us 3.04us 128.31us 111.62us
insertFront(1024) 3.14us 3.10us 129.76us 109.75us
insertFront(10240) 3.72us 3.68us 153.54us 129.10us
insertFront(102400) 9.35us 9.30us 386.54us 332.21us
insertFront(1024000) 108.52us 109.90us 3.01ms 2.75ms
pushBack(16) 17.18ns 4.28ns 43.32ns 22.47ns
pushBack(128) 17.21ns 4.31ns 34.87ns 25.60ns
pushBack(1024) 17.23ns 4.26ns 31.76ns 21.53ns
pushBack(10240) 17.13ns 4.33ns 31.40ns 27.04ns
pushBack(102400) 17.24ns 4.34ns 42.96ns 27.41ns
pushBack(1024000) 18.77ns 6.00ns 100.87ns 88.54ns
----------------------------------------------------------------
*/
template <typename T, size_t N>
using small_vector = folly::small_vector<T, N>;
// using small_vector = boost::container::small_vector<T, N>;
using small_vector = boost::container::small_vector<T, N>;
} // namespace dwarfs

View File

@ -137,6 +137,11 @@ class performance_monitor_impl : public performance_monitor {
, end{end}
, context{ctx.begin(), ctx.end()} {}
// TODO: workaround for older boost small_vector
std::span<uint64_t const> context_span() const {
return std::span{context.data(), context.size()};
}
timer_id id;
time_type start;
time_type end;
@ -286,7 +291,7 @@ class performance_monitor_impl : public performance_monitor {
for (auto const& ev : *evs) {
events.emplace_back(ev.id, it->second, 'B', ev.start - start_time_,
ev.context);
ev.context_span());
events.emplace_back(ev.id, it->second, 'E', ev.end - start_time_);
}
}