1
0
Fork 0

Feature/improve refcount performance (#8783)

This commit is contained in:
Tobias Gödderz 2019-04-18 14:32:30 +02:00 committed by Jan
parent 7de7e35c33
commit 425b40d9a2
3 changed files with 29 additions and 16 deletions

View File

@ -97,7 +97,7 @@ class InputAqlItemRow {
return a; return a;
} }
std::size_t getNrRegisters() const { return block().getNrRegs(); } std::size_t getNrRegisters() const noexcept { return block().getNrRegs(); }
bool operator==(InputAqlItemRow const& other) const noexcept { bool operator==(InputAqlItemRow const& other) const noexcept {
TRI_ASSERT(isInitialized()); TRI_ASSERT(isInitialized());
@ -149,12 +149,12 @@ class InputAqlItemRow {
private: private:
inline AqlItemBlock& block() { inline AqlItemBlock& block() noexcept {
TRI_ASSERT(_block != nullptr); TRI_ASSERT(_block != nullptr);
return *_block; return *_block;
} }
inline AqlItemBlock const& block() const { inline AqlItemBlock const& block() const noexcept {
TRI_ASSERT(_block != nullptr); TRI_ASSERT(_block != nullptr);
return *_block; return *_block;
} }

View File

@ -27,14 +27,16 @@
using namespace arangodb; using namespace arangodb;
using namespace arangodb::aql; using namespace arangodb::aql;
void SharedAqlItemBlockPtr::decrRefCount() noexcept { /*
if (_aqlItemBlock != nullptr) { * returnBlock() and itemBlockManager() cannot be moved into the header file due
_aqlItemBlock->decrRefCount(); * to the circular dependency between SharedAqlItemBlockPtr and
if (_aqlItemBlock->getRefCount() == 0) { * AqlItemBlockManager. However, by extracting returnBlock(), at least the often
itemBlockManager().returnBlock(_aqlItemBlock); * called part of decrRefCount() can by inlined.
TRI_ASSERT(_aqlItemBlock == nullptr); */
}
} void SharedAqlItemBlockPtr::returnBlock() noexcept {
itemBlockManager().returnBlock(_aqlItemBlock);
TRI_ASSERT(_aqlItemBlock == nullptr);
} }
AqlItemBlockManager& SharedAqlItemBlockPtr::itemBlockManager() const noexcept { AqlItemBlockManager& SharedAqlItemBlockPtr::itemBlockManager() const noexcept {

View File

@ -62,8 +62,8 @@ class SharedAqlItemBlockPtr {
inline void swap(SharedAqlItemBlockPtr& other) noexcept; inline void swap(SharedAqlItemBlockPtr& other) noexcept;
inline bool operator==(std::nullptr_t) noexcept; inline bool operator==(std::nullptr_t) const noexcept;
inline bool operator!=(std::nullptr_t) noexcept; inline bool operator!=(std::nullptr_t) const noexcept;
inline bool operator==(SharedAqlItemBlockPtr const&) const noexcept; inline bool operator==(SharedAqlItemBlockPtr const&) const noexcept;
inline bool operator!=(SharedAqlItemBlockPtr const&) const noexcept; inline bool operator!=(SharedAqlItemBlockPtr const&) const noexcept;
@ -71,10 +71,12 @@ class SharedAqlItemBlockPtr {
private: private:
inline void incrRefCount() const noexcept; inline void incrRefCount() const noexcept;
// decrRefCount returns ("frees") _aqlItemBlock if the ref count reaches 0 // decrRefCount returns ("frees") _aqlItemBlock if the ref count reaches 0
void decrRefCount() noexcept; inline void decrRefCount() noexcept;
AqlItemBlockManager& itemBlockManager() const noexcept; AqlItemBlockManager& itemBlockManager() const noexcept;
void returnBlock() noexcept;
private: private:
AqlItemBlock* _aqlItemBlock; AqlItemBlock* _aqlItemBlock;
}; };
@ -162,11 +164,11 @@ void SharedAqlItemBlockPtr::incrRefCount() const noexcept {
} }
} }
bool SharedAqlItemBlockPtr::operator==(std::nullptr_t) noexcept { bool SharedAqlItemBlockPtr::operator==(std::nullptr_t) const noexcept {
return _aqlItemBlock == nullptr; return _aqlItemBlock == nullptr;
} }
bool SharedAqlItemBlockPtr::operator!=(std::nullptr_t) noexcept { bool SharedAqlItemBlockPtr::operator!=(std::nullptr_t) const noexcept {
return _aqlItemBlock != nullptr; return _aqlItemBlock != nullptr;
} }
@ -196,6 +198,15 @@ void SharedAqlItemBlockPtr::swap(SharedAqlItemBlockPtr& other) noexcept {
other._aqlItemBlock = tmp; other._aqlItemBlock = tmp;
} }
void arangodb::aql::SharedAqlItemBlockPtr::decrRefCount() noexcept {
if (_aqlItemBlock != nullptr) {
_aqlItemBlock->decrRefCount();
if (_aqlItemBlock->getRefCount() == 0) {
returnBlock();
}
}
}
} // namespace aql } // namespace aql
} // namespace arangodb } // namespace arangodb