diff --git a/include/dwarfs/inode_fragments.h b/include/dwarfs/inode_fragments.h index db2f4f88..7a2634f0 100644 --- a/include/dwarfs/inode_fragments.h +++ b/include/dwarfs/inode_fragments.h @@ -47,7 +47,10 @@ class single_inode_fragment { void add_chunk(size_t block, size_t offset, size_t size); - std::span chunks() const { return chunks_; } + std::span 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 span() const { return fragments_; } + std::span 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(); } diff --git a/include/dwarfs/internal/offset_cache.h b/include/dwarfs/internal/offset_cache.h index a4b9d06a..8b60efd9 100644 --- a/include/dwarfs/internal/offset_cache.h +++ b/include/dwarfs/internal/offset_cache.h @@ -151,7 +151,10 @@ class basic_offset_cache { chunk_index_type first_index() const { return first_index_; } - std::span offsets() const { return offsets_; } + std::span offsets() const { + // TODO: workaround for older boost small_vector + return std::span(offsets_.data(), offsets_.size()); + } private: small_vector offsets_; diff --git a/include/dwarfs/performance_monitor.h b/include/dwarfs/performance_monitor.h index e80ec5a5..c2a647a1 100644 --- a/include/dwarfs/performance_monitor.h +++ b/include/dwarfs/performance_monitor.h @@ -86,7 +86,10 @@ class performance_monitor_proxy { ~section_timer() { if (mon_) { mon_->add_sample(id_, start_, - context_ ? *context_ : std::span{}); + context_ + // TODO: workaround for older boost small_vector + ? std::span{context_->data(), context_->size()} + : std::span{}); } } diff --git a/include/dwarfs/small_vector.h b/include/dwarfs/small_vector.h index ec2bb524..75b9da11 100644 --- a/include/dwarfs/small_vector.h +++ b/include/dwarfs/small_vector.h @@ -21,13 +21,43 @@ #pragma once -#include -// #include +#include 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 -using small_vector = folly::small_vector; -// using small_vector = boost::container::small_vector; +using small_vector = boost::container::small_vector; } // namespace dwarfs diff --git a/src/dwarfs/performance_monitor.cpp b/src/dwarfs/performance_monitor.cpp index fe3c985a..1ef1ff76 100644 --- a/src/dwarfs/performance_monitor.cpp +++ b/src/dwarfs/performance_monitor.cpp @@ -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 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_); } }