summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2023-06-22 13:03:08 +0200
committerTor Egge <Tor.Egge@online.no>2023-06-22 13:03:08 +0200
commit9635ed7379c3244a4a32de90bc261d54a1486282 (patch)
treef41811baf8b1483ac53bee00063ff5c4ae026ee7 /vespalib
parent67fe9c6d3ee4ec4ef07596f3da27b1e291a2189d (diff)
Use faster way to get entry size.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/datastore/array_store.h2
-rw-r--r--vespalib/src/vespa/vespalib/datastore/buffer_type.cpp6
-rw-r--r--vespalib/src/vespa/vespalib/datastore/buffer_type.h1
-rw-r--r--vespalib/src/vespa/vespalib/datastore/bufferstate.h14
-rw-r--r--vespalib/src/vespa/vespalib/datastore/datastorebase.cpp6
-rw-r--r--vespalib/src/vespa/vespalib/datastore/dynamic_array_buffer_type.h1
-rw-r--r--vespalib/src/vespa/vespalib/datastore/dynamic_array_buffer_type.hpp7
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h4
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h2
9 files changed, 33 insertions, 10 deletions
diff --git a/vespalib/src/vespa/vespalib/datastore/array_store.h b/vespalib/src/vespa/vespalib/datastore/array_store.h
index f5c30c90c5b..0490687aeb8 100644
--- a/vespalib/src/vespa/vespalib/datastore/array_store.h
+++ b/vespalib/src/vespa/vespalib/datastore/array_store.h
@@ -126,7 +126,7 @@ public:
return get_dynamic_array<typename TypeMapper::DynamicBufferType>(bufferAndMeta.get_buffer_acquire(), internalRef.offset(), bufferAndMeta.get_entry_size());
}
}
- return getSmallArray(internalRef, bufferAndMeta.getArraySize());
+ return getSmallArray(internalRef, bufferAndMeta.get_array_size());
} else {
return getLargeArray(internalRef);
}
diff --git a/vespalib/src/vespa/vespalib/datastore/buffer_type.cpp b/vespalib/src/vespa/vespalib/datastore/buffer_type.cpp
index bb34c5d0f9d..90f9334da77 100644
--- a/vespalib/src/vespa/vespalib/datastore/buffer_type.cpp
+++ b/vespalib/src/vespa/vespalib/datastore/buffer_type.cpp
@@ -117,6 +117,12 @@ BufferTypeBase::get_memory_allocator() const
return nullptr;
}
+bool
+BufferTypeBase::is_dynamic_array_buffer_type() const noexcept
+{
+ return false;
+}
+
void
BufferTypeBase::clamp_max_entries(uint32_t max_entries)
{
diff --git a/vespalib/src/vespa/vespalib/datastore/buffer_type.h b/vespalib/src/vespa/vespalib/datastore/buffer_type.h
index 3370bd47fad..c79651c3ba2 100644
--- a/vespalib/src/vespa/vespalib/datastore/buffer_type.h
+++ b/vespalib/src/vespa/vespalib/datastore/buffer_type.h
@@ -64,6 +64,7 @@ public:
virtual void on_free(EntryCount used_entries);
void resume_primary_buffer(uint32_t buffer_id, std::atomic<EntryCount>* used_entries, std::atomic<EntryCount>* dead_entries);
virtual const alloc::MemoryAllocator* get_memory_allocator() const;
+ virtual bool is_dynamic_array_buffer_type() const noexcept;
/**
* Calculate number of entries to allocate for new buffer given how many free entries are needed.
diff --git a/vespalib/src/vespa/vespalib/datastore/bufferstate.h b/vespalib/src/vespa/vespalib/datastore/bufferstate.h
index 289be32e19b..1b9db616888 100644
--- a/vespalib/src/vespa/vespalib/datastore/bufferstate.h
+++ b/vespalib/src/vespa/vespalib/datastore/bufferstate.h
@@ -137,24 +137,28 @@ public:
void* get_buffer_relaxed() noexcept { return _buffer.load(std::memory_order_relaxed); }
const void* get_buffer_acquire() const noexcept { return _buffer.load(std::memory_order_acquire); }
uint32_t getTypeId() const { return _typeId; }
- uint32_t getArraySize() const { return _arraySize; }
+ uint32_t get_array_size() const { return _array_size; }
BufferState * get_state_relaxed() { return _state.load(std::memory_order_relaxed); }
const BufferState * get_state_acquire() const { return _state.load(std::memory_order_acquire); }
- uint32_t get_entry_size() const { return get_state_acquire()->getTypeHandler()->entry_size(); }
+ uint32_t get_entry_size() const noexcept { return _entry_size; }
void setTypeId(uint32_t typeId) { _typeId = typeId; }
- void setArraySize(uint32_t arraySize) { _arraySize = arraySize; }
+ void set_array_size(uint32_t arraySize) { _array_size = arraySize; }
+ void set_entry_size(uint32_t entry_size) noexcept { _entry_size = entry_size; }
void set_state(BufferState * state) { _state.store(state, std::memory_order_release); }
private:
BufferAndMeta(void* buffer, BufferState * state, uint32_t typeId, uint32_t arraySize)
: _buffer(buffer),
_state(state),
_typeId(typeId),
- _arraySize(arraySize)
+ _array_size(arraySize)
{ }
std::atomic<void*> _buffer;
std::atomic<BufferState*> _state;
uint32_t _typeId;
- uint32_t _arraySize;
+ union {
+ uint32_t _array_size; // Valid unless buffer type is dynamic array buffer type
+ uint32_t _entry_size; // Valid if buffer type is dynamic array buffer type
+ };
};
}
diff --git a/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp b/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp
index 75ffe855a32..5926132427c 100644
--- a/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp
+++ b/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp
@@ -415,7 +415,11 @@ DataStoreBase::on_active(uint32_t bufferId, uint32_t typeId, size_t entries_need
assert(state->isFree());
state->on_active(bufferId, typeId, _typeHandlers[typeId], entries_needed, bufferMeta.get_atomic_buffer());
bufferMeta.setTypeId(typeId);
- bufferMeta.setArraySize(state->getArraySize());
+ if (_typeHandlers[typeId]->is_dynamic_array_buffer_type()) {
+ bufferMeta.set_entry_size(_typeHandlers[typeId]->entry_size());
+ } else {
+ bufferMeta.set_array_size(state->getArraySize());
+ }
if (_freeListsEnabled && state->isActive() && !state->getCompacting()) {
state->enable_free_list(_free_lists[state->getTypeId()]);
}
diff --git a/vespalib/src/vespa/vespalib/datastore/dynamic_array_buffer_type.h b/vespalib/src/vespa/vespalib/datastore/dynamic_array_buffer_type.h
index fbd3c2361d1..2f0f0ae0e26 100644
--- a/vespalib/src/vespa/vespalib/datastore/dynamic_array_buffer_type.h
+++ b/vespalib/src/vespa/vespalib/datastore/dynamic_array_buffer_type.h
@@ -59,6 +59,7 @@ public:
static const ElemType* get_entry(const void* buffer, size_t offset, uint32_t entry_size) noexcept { return reinterpret_cast<const ElemType*>(static_cast<const char*>(buffer) + offset * entry_size + entry_bias); }
static uint32_t get_dynamic_array_size(const ElemType* buffer) noexcept { return *(reinterpret_cast<const uint32_t*>(buffer) - 1); }
static void set_dynamic_array_size(ElemType* buffer, uint32_t array_size) noexcept { *(reinterpret_cast<uint32_t*>(buffer) - 1) = array_size; }
+ bool is_dynamic_array_buffer_type() const noexcept override;
};
extern template class DynamicArrayBufferType<char>;
diff --git a/vespalib/src/vespa/vespalib/datastore/dynamic_array_buffer_type.hpp b/vespalib/src/vespa/vespalib/datastore/dynamic_array_buffer_type.hpp
index bf3235a6b97..3ed26db4e7f 100644
--- a/vespalib/src/vespa/vespalib/datastore/dynamic_array_buffer_type.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/dynamic_array_buffer_type.hpp
@@ -116,4 +116,11 @@ DynamicArrayBufferType<ElemT>::get_memory_allocator() const
return _memory_allocator.get();
}
+template <typename ElemT>
+bool
+DynamicArrayBufferType<ElemT>::is_dynamic_array_buffer_type() const noexcept
+{
+ return true;
+}
+
}
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h b/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h
index d3348950891..102808f7629 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h
@@ -117,7 +117,7 @@ public:
auto &state = _store.getBufferMeta(iRef.bufferId());
auto type_id = state.getTypeId();
if (type_id != 0) {
- return *reinterpret_cast<const UniqueStoreEntryBase *>(_store.template getEntryArray<char>(iRef, state.getArraySize()));
+ return *reinterpret_cast<const UniqueStoreEntryBase *>(_store.template getEntryArray<char>(iRef, state.get_array_size()));
} else {
return *_store.template getEntry<WrappedExternalEntryType>(iRef);
}
@@ -127,7 +127,7 @@ public:
auto &state = _store.getBufferMeta(iRef.bufferId());
auto type_id = state.getTypeId();
if (type_id != 0) {
- return reinterpret_cast<const UniqueStoreSmallStringEntry *>(_store.template getEntryArray<char>(iRef, state.getArraySize()))->value();
+ return reinterpret_cast<const UniqueStoreSmallStringEntry *>(_store.template getEntryArray<char>(iRef, state.get_array_size()))->value();
} else {
return _store.template getEntry<WrappedExternalEntryType>(iRef)->value().c_str();
}
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h b/vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h
index e507132a085..e71dcd3aafb 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h
@@ -28,7 +28,7 @@ protected:
const auto &meta = _store.getBufferMeta(iRef.bufferId());
auto type_id = meta.getTypeId();
if (type_id != 0) {
- return reinterpret_cast<const UniqueStoreSmallStringEntry *>(_store.template getEntryArray<char>(iRef, meta.getArraySize()))->value();
+ return reinterpret_cast<const UniqueStoreSmallStringEntry *>(_store.template getEntryArray<char>(iRef, meta.get_array_size()))->value();
} else {
return _store.template getEntry<WrappedExternalEntryType>(iRef)->value().c_str();
}