diff options
| author | Dan Engelbrecht <[email protected]> | 2022-04-28 22:17:20 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-04-28 22:17:20 +0200 |
| commit | 8b7d5557dfacd0527d30bccaf4b9dbeb060be674 (patch) | |
| tree | e8e733d73f4f251a8bf3daa043e8e299ed44ed00 | |
| parent | Merge pull request #81 from EpicGames/de/use-bulk-fetch-from-upstream-on-getc... (diff) | |
| parent | Reduce risk of reallocating backing std::vector in CbWriter::AddBinary (diff) | |
| download | zen-8b7d5557dfacd0527d30bccaf4b9dbeb060be674.tar.xz zen-8b7d5557dfacd0527d30bccaf4b9dbeb060be674.zip | |
Merge pull request #83 from EpicGames/de/minor-optimizationsv1.0.0.7
Minor optimizations to reduce overhead during high load
| -rw-r--r-- | zencore/compactbinarybuilder.cpp | 5 | ||||
| -rw-r--r-- | zencore/iobuffer.cpp | 12 | ||||
| -rw-r--r-- | zenserver/upstream/upstreamcache.cpp | 2 |
3 files changed, 14 insertions, 5 deletions
diff --git a/zencore/compactbinarybuilder.cpp b/zencore/compactbinarybuilder.cpp index 5111504e1..1d2ba45df 100644 --- a/zencore/compactbinarybuilder.cpp +++ b/zencore/compactbinarybuilder.cpp @@ -436,9 +436,10 @@ CbWriter::AddNull() void CbWriter::AddBinary(const void* const Value, const uint64_t Size) { + const size_t SizeByteCount = MeasureVarUInt(Size); + Data.reserve(Data.size() + 1 + SizeByteCount + Size); BeginField(); - const uint32_t SizeByteCount = MeasureVarUInt(Size); - const int64_t SizeOffset = Data.size(); + const size_t SizeOffset = Data.size(); Data.resize(Data.size() + SizeByteCount); WriteVarUInt(Size, Data.data() + SizeOffset); Data.insert(Data.end(), static_cast<const uint8_t*>(Value), static_cast<const uint8_t*>(Value) + Size); diff --git a/zencore/iobuffer.cpp b/zencore/iobuffer.cpp index 8a3ab8427..c069aa0f1 100644 --- a/zencore/iobuffer.cpp +++ b/zencore/iobuffer.cpp @@ -226,7 +226,15 @@ IoBufferExtendedCore::~IoBufferExtendedCore() m_DataPtr = nullptr; } -static RwLock g_MappingLock; +static RwLock g_MappingLock[0x40]; + +static RwLock& +MappingLockForInstance(const IoBufferExtendedCore* instance) +{ + intptr_t base = (intptr_t)instance; + size_t lock_index = ((base >> 8) ^ (base >> 16)) & 0x3f; + return g_MappingLock[lock_index]; +} void IoBufferExtendedCore::Materialize() const @@ -237,7 +245,7 @@ IoBufferExtendedCore::Materialize() const if (m_Flags.load(std::memory_order_acquire) & kIsMaterialized) return; - RwLock::ExclusiveLockScope _(g_MappingLock); + RwLock::ExclusiveLockScope _(MappingLockForInstance(this)); // Someone could have gotten here first // We can use memory_order_relaxed on this load because the mutex has already provided the fence diff --git a/zenserver/upstream/upstreamcache.cpp b/zenserver/upstream/upstreamcache.cpp index da0743f0a..dba80faa9 100644 --- a/zenserver/upstream/upstreamcache.cpp +++ b/zenserver/upstream/upstreamcache.cpp @@ -1451,7 +1451,7 @@ public: virtual void EnqueueUpstream(UpstreamCacheRecord CacheRecord) override { - if (m_RunState.IsRunning && m_Options.WriteUpstream) + if (m_RunState.IsRunning && m_Options.WriteUpstream && m_Endpoints.size() > 0) { if (!m_UpstreamThreads.empty()) { |