From 3f4f049ac015c695a965142e7b1180eae83ae781 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期四, 25 三月 2021 16:18:26 +0800 Subject: [PATCH] reason for speed change; refactor. --- src/shm_queue.cpp | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shm_queue.cpp b/src/shm_queue.cpp index 1446446..f770afc 100644 --- a/src/shm_queue.cpp +++ b/src/shm_queue.cpp @@ -48,8 +48,6 @@ bool ShmMsgQueue::Send(const MQId &remote_id, const Msg &msg, const int timeout_ms) { Queue *remote = find(MsgQIdToName(remote_id)); - - return remote && remote->Write(msg, timeout_ms); if(!remote) { return false; @@ -65,6 +63,11 @@ bool ShmMsgQueue::Send(const MQId &remote_id, const void *data, const size_t size, const int timeout_ms) { + // Test shows that in the 2 cases: + // 1) build msg first, then find remote queue; + // 2) find remote queue first, then build msg; + // 1 is about 50% faster than 2, maybe cache related. + Msg msg; if (msg.Build(shm(), Id(), data, size, false)) { if (Send(remote_id, msg, timeout_ms)) { -- Gitblit v1.8.0