Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pp/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ http_archive(
build_file = "//third_party:parallel_hashmap.BUILD",
patches = [
"//third_party/patches/parallel_hashmap:phmap_base.h.patch",
"//third_party/patches/parallel_hashmap:btree.h.patch",
],
sha256 = "b61435437713e2d98ce2a5539a0bff7e6e9e6a6b9fe507dbf490a852b8c2904f",
strip_prefix = "parallel-hashmap-1.35",
Expand Down
4 changes: 2 additions & 2 deletions pp/bare_bones/concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ concept has_size = requires(const T& t) {
};

template <class T>
concept has_reserve = requires(T& r) {
{ r.reserve(size_t{}) };
concept has_reserve = requires(T& r, uint32_t n) {
{ r.reserve(n) } -> std::same_as<void>;
};

template <class Clock>
Expand Down
40 changes: 7 additions & 33 deletions pp/bare_bones/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,6 @@ template <class T>
struct MemoryControlBlock {
using SizeType = uint32_t;

MemoryControlBlock() = default;
MemoryControlBlock(const MemoryControlBlock&) = delete;
MemoryControlBlock(MemoryControlBlock&& other) noexcept : data(std::exchange(other.data, nullptr)), data_size(std::exchange(other.data_size, 0)) {}

MemoryControlBlock& operator=(const MemoryControlBlock&) = delete;
PROMPP_ALWAYS_INLINE MemoryControlBlock& operator=(MemoryControlBlock&& other) noexcept {
if (this != &other) [[likely]] {
data = std::exchange(other.data, nullptr);
data_size = std::exchange(other.data_size, 0);
}

return *this;
}

T* data{};
SizeType data_size{};
};
Expand All @@ -123,22 +109,6 @@ template <class T>
struct MemoryControlBlockWithItemCount {
using SizeType = uint32_t;

MemoryControlBlockWithItemCount() = default;
MemoryControlBlockWithItemCount(const MemoryControlBlockWithItemCount&) = delete;
MemoryControlBlockWithItemCount(MemoryControlBlockWithItemCount&& other) noexcept
: data(std::exchange(other.data, nullptr)), data_size(std::exchange(other.data_size, 0)), items_count(std::exchange(other.items_count, 0)) {}

MemoryControlBlockWithItemCount& operator=(const MemoryControlBlockWithItemCount&) = delete;
PROMPP_ALWAYS_INLINE MemoryControlBlockWithItemCount& operator=(MemoryControlBlockWithItemCount&& other) noexcept {
if (this != &other) [[likely]] {
data = std::exchange(other.data, nullptr);
data_size = std::exchange(other.data_size, 0);
items_count = std::exchange(other.items_count, 0);
}

return *this;
}

T* data{};
SizeType data_size{};
SizeType items_count{};
Expand All @@ -152,7 +122,7 @@ class Memory : public GenericMemory<Memory<ControlBlock, T>, typename ControlBlo

PROMPP_ALWAYS_INLINE Memory() noexcept = default;
PROMPP_ALWAYS_INLINE Memory(const Memory& o) noexcept { copy(o); }
PROMPP_ALWAYS_INLINE Memory(Memory&& o) noexcept = default;
PROMPP_ALWAYS_INLINE Memory(Memory&& o) noexcept : control_block_(std::exchange(o.control_block_, {})) {};
PROMPP_ALWAYS_INLINE ~Memory() noexcept { std::free(control_block_.data); }

PROMPP_ALWAYS_INLINE Memory& operator=(const Memory& o) noexcept {
Expand All @@ -166,7 +136,7 @@ class Memory : public GenericMemory<Memory<ControlBlock, T>, typename ControlBlo
PROMPP_ALWAYS_INLINE Memory& operator=(Memory&& o) noexcept {
if (this != &o) [[likely]] {
std::free(control_block_.data);
control_block_ = std::move(o.control_block_);
control_block_ = std::exchange(o.control_block_, {});
}

return *this;
Expand Down Expand Up @@ -202,7 +172,11 @@ class Memory : public GenericMemory<Memory<ControlBlock, T>, typename ControlBlo
PROMPP_ALWAYS_INLINE void copy(const Memory& o) noexcept {
static_assert(IsTriviallyCopyable<T>::value, "it's not allowed to copy memory for non trivially copyable types");

resize(o.control_block_.data_size);
T* data = control_block_.data;
control_block_ = o.control_block_;
control_block_.data = data;

resize(control_block_.data_size);

PRAGMA_DIAGNOSTIC(push)
PRAGMA_DIAGNOSTIC(ignored DIAGNOSTIC_CLASS_MEMACCESS)
Expand Down
19 changes: 6 additions & 13 deletions pp/bare_bones/snug_composite.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,9 @@ class GenericDecodingTable {
struct LessComparator {
using is_transparent = void;

PROMPP_ALWAYS_INLINE explicit LessComparator(const GenericDecodingTable* decoding_table, bool* enabled) noexcept
: decoding_table_(decoding_table), enabled_(enabled) {}
PROMPP_ALWAYS_INLINE explicit LessComparator(const GenericDecodingTable* decoding_table) noexcept : decoding_table_(decoding_table) {}

PROMPP_ALWAYS_INLINE bool operator()(const Proxy& a, const Proxy& b) const noexcept {
if (!*enabled_) {
return true;
}

return decoding_table_->items_[a].composite(decoding_table_->data_) < decoding_table_->items_[b].composite(decoding_table_->data_);
}

Expand All @@ -134,7 +129,6 @@ class GenericDecodingTable {

private:
const GenericDecodingTable* decoding_table_;
bool* enabled_;
};

template <class DecodingTable>
Expand Down Expand Up @@ -263,7 +257,7 @@ class GenericDecodingTable {

[[nodiscard]] PROMPP_ALWAYS_INLINE Hasher hasher() const noexcept { return Hasher(this); }
[[nodiscard]] PROMPP_ALWAYS_INLINE EqualityComparator equality_comparator() const noexcept { return EqualityComparator(this); }
[[nodiscard]] PROMPP_ALWAYS_INLINE LessComparator less_comparator(bool* enabled) const noexcept { return LessComparator(this, enabled); }
[[nodiscard]] PROMPP_ALWAYS_INLINE LessComparator less_comparator() const noexcept { return LessComparator(this); }

data_type data_;
Vector<Filament<Vector>> items_;
Expand Down Expand Up @@ -293,7 +287,8 @@ class GenericDecodingTable {

inline __attribute__((always_inline)) const auto& items() const noexcept { return items_; }

PROMPP_ALWAYS_INLINE void reserve(const GenericDecodingTable& other) {
template <class DerivedOther, template <template <class> class> class FilamentOther, template <class> class VectorOther>
PROMPP_ALWAYS_INLINE void reserve(const GenericDecodingTable<DerivedOther, FilamentOther, VectorOther>& other) {
items_.reserve(other.items_.size());
data_.reserve(other.data_);
}
Expand Down Expand Up @@ -791,7 +786,6 @@ class OrderedEncodingBimap : public GenericDecodingTable<OrderedEncodingBimap<Fi

using Set = phmap::btree_set<typename Base::Proxy, typename Base::LessComparator>;
Set set_;
bool set_soring_enabled_{true};

protected:
PROMPP_ALWAYS_INLINE void after_items_load_impl(uint32_t first_loaded_id) noexcept {
Expand All @@ -801,7 +795,7 @@ class OrderedEncodingBimap : public GenericDecodingTable<OrderedEncodingBimap<Fi
}

public:
inline __attribute__((always_inline)) OrderedEncodingBimap() noexcept : set_({}, Base::less_comparator(&set_soring_enabled_)) {}
inline __attribute__((always_inline)) OrderedEncodingBimap() noexcept : set_({}, Base::less_comparator()) {}

OrderedEncodingBimap(const OrderedEncodingBimap&) = delete;
OrderedEncodingBimap(OrderedEncodingBimap&&) = delete;
Expand Down Expand Up @@ -897,7 +891,6 @@ class EncodingBimapWithOrderedAccess : public GenericDecodingTable<EncodingBimap

using OrderedSet = phmap::btree_set<typename Base::Proxy, typename Base::LessComparator>;
OrderedSet ordered_set_;
bool ordered_set_soring_enabled_{true};

using Set = phmap::flat_hash_set<typename Base::Proxy, typename Base::Hasher, typename Base::EqualityComparator>;
Set set_;
Expand All @@ -912,7 +905,7 @@ class EncodingBimapWithOrderedAccess : public GenericDecodingTable<EncodingBimap

public:
inline __attribute__((always_inline)) EncodingBimapWithOrderedAccess() noexcept
: ordered_set_({}, Base::less_comparator(&ordered_set_soring_enabled_)), set_({}, 0, Base::hasher(), Base::equality_comparator()) {}
: ordered_set_({}, Base::less_comparator()), set_({}, 0, Base::hasher(), Base::equality_comparator()) {}

EncodingBimapWithOrderedAccess(const EncodingBimapWithOrderedAccess&) = delete;
EncodingBimapWithOrderedAccess(EncodingBimapWithOrderedAccess&&) = delete;
Expand Down
102 changes: 102 additions & 0 deletions pp/bare_bones/tests/bitset_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,106 @@ TEST_F(BitsetFixture, PopcountAfterResizeInNextUint64) {
EXPECT_EQ(0U, bs_.popcount());
}

class BitsetConstructorsFixture : public BitsetFixture {};

TEST_F(BitsetConstructorsFixture, CopyConstructor) {
// Arrange
bs_.resize(1001);
bs_.set(1);
bs_.set(100);
bs_.set(1000);

// Act
BareBones::Bitset bs_copy(bs_);

// Assert
EXPECT_TRUE(std::ranges::equal(bs_, bs_copy));
}

TEST_F(BitsetConstructorsFixture, MoveConstructor) {
// Arrange
bs_.resize(1001);
bs_.set(1);
bs_.set(100);
bs_.set(1000);

// Act
BareBones::Bitset bs_move(std::move(bs_));

// Assert
EXPECT_TRUE(std::ranges::equal(bs_move, std::initializer_list<uint32_t>{1, 100, 1000}));
}

TEST_F(BitsetConstructorsFixture, CopyAssignment) {
// Arrange
bs_.resize(1001);

bs_.set(1);
bs_.set(100);
bs_.set(1000);

// Act
BareBones::Bitset bs_copy = bs_;

// Assert
EXPECT_TRUE(std::ranges::equal(bs_, bs_copy));
}

TEST_F(BitsetConstructorsFixture, CopyAssignmentNonEmpty) {
// Arrange
bs_.resize(1001);

bs_.set(1);
bs_.set(100);
bs_.set(1000);

BareBones::Bitset bs_copy;
bs_copy.resize(3);
bs_copy.set(0);
bs_copy.set(1);
bs_copy.set(2);

// Act
bs_copy = bs_;

// Assert
EXPECT_TRUE(std::ranges::equal(bs_, bs_copy));
}

TEST_F(BitsetConstructorsFixture, MoveAssignment) {
// Arrange
bs_.resize(1001);

bs_.set(1);
bs_.set(100);
bs_.set(1000);

// Act
BareBones::Bitset bs_move = std::move(bs_);

// Assert
EXPECT_TRUE(std::ranges::equal(bs_move, std::initializer_list<uint32_t>{1, 100, 1000}));
}

TEST_F(BitsetConstructorsFixture, MoveAssignmentNonEmpty) {
// Arrange
bs_.resize(1001);

bs_.set(1);
bs_.set(100);
bs_.set(1000);

BareBones::Bitset bs_move;
bs_move.resize(3);
bs_move.set(0);
bs_move.set(1);
bs_move.set(2);

// Act
bs_move = std::move(bs_);

// Assert
EXPECT_TRUE(std::ranges::equal(bs_move, std::initializer_list<uint32_t>{1, 100, 1000}));
}

} // namespace
42 changes: 42 additions & 0 deletions pp/bare_bones/tests/memory_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using BareBones::AllocationSizeCalculator;
using BareBones::DefaultReallocator;
using BareBones::Memory;
using BareBones::MemoryControlBlock;
using BareBones::MemoryControlBlockWithItemCount;
using BareBones::SharedMemory;
using BareBones::SharedPtr;

Expand Down Expand Up @@ -136,6 +137,47 @@ TEST_F(MemoryFixture, MoveOperator) {
EXPECT_EQ(memory_size, memory2.size());
}

class MemoryWithItemCountFixture : public ::testing::Test {
protected:
Memory<MemoryControlBlockWithItemCount, uint8_t> memory_;
};

TEST_F(MemoryWithItemCountFixture, CopyConstructor) {
// Arrange
memory_.resize_to_fit_at_least(1);
std::iota(memory_.begin(), memory_.end(), uint8_t{});
memory_.control_block().items_count = 100;

// Act
const auto memory2 = memory_;

// Assert
EXPECT_NE(memory2, memory_);
ASSERT_EQ(memory_.size(), memory2.size());
ASSERT_EQ(memory_.control_block().data_size, memory2.control_block().data_size);
ASSERT_EQ(memory_.control_block().items_count, memory2.control_block().items_count);
EXPECT_TRUE(std::ranges::equal(memory2, memory_));
}

TEST_F(MemoryWithItemCountFixture, CopyOperator) {
// Arrange
memory_.resize_to_fit_at_least(1);
std::iota(memory_.begin(), memory_.end(), uint8_t{});
memory_.control_block().items_count = 100;

// Act
decltype(memory_) memory2;
memory2.resize_to_fit_at_least(1);
memory2 = memory_;

// Assert
EXPECT_NE(memory2, memory_);
ASSERT_EQ(memory_.size(), memory2.size());
ASSERT_EQ(memory_.control_block().data_size, memory2.control_block().data_size);
ASSERT_EQ(memory_.control_block().items_count, memory2.control_block().items_count);
EXPECT_TRUE(std::ranges::equal(memory2, memory_));
}

class SharedPtrFixture : public ::testing::Test {
protected:
template <class T>
Expand Down
6 changes: 4 additions & 2 deletions pp/entrypoint/primitives_lss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ extern "C" void prompp_create_readonly_lss(void* args, void* res) {
}

extern "C" void prompp_primitives_lss_copy_added_series(uint64_t source_lss, uint64_t destination_lss) {
series_index::QueryableEncodingBimapCopier copier(std::get<QueryableEncodingBimap>(*std::bit_cast<entrypoint::head::LssVariant*>(source_lss)),
std::get<QueryableEncodingBimap>(*std::bit_cast<entrypoint::head::LssVariant*>(destination_lss)));
const auto& src = std::get<QueryableEncodingBimap>(*std::bit_cast<entrypoint::head::LssVariant*>(source_lss));
auto& dst = std::get<QueryableEncodingBimap>(*std::bit_cast<entrypoint::head::LssVariant*>(destination_lss));

series_index::QueryableEncodingBimapCopier copier(src, src.sorting_index(), dst.added_series(), dst);
copier.copy_added_series_and_build_indexes();
}
11 changes: 11 additions & 0 deletions pp/performance_tests/benchmarks/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ cc_binary(
"@google_benchmark//:benchmark_main",
],
)

cc_binary(
name = "copy_lss",
srcs = ["queryable_encoding_bimap_copy_benchmark.cpp"],
malloc = "@jemalloc",
deps = [
"//:performance_tests_headers",
"@google_benchmark//:benchmark_main",
"//:entrypoint",
],
)
Loading
Loading