[ntcore] Reduce initial connection overhead

Mixing the announce and value messages causes significant downstream
inefficiency in both time and space.
This commit is contained in:
Peter Johnson
2023-02-11 22:43:56 -08:00
parent 804e5ce236
commit b30664d630

View File

@@ -650,6 +650,11 @@ void ClientData4Base::ClientSubscribe(int64_t subuid,
}
// see if this immediately subscribes to any topics
// for transmit efficiency, we want to batch announcements and values, so
// send announcements in first loop and remember what we want to send in
// second loop.
std::vector<TopicData*> dataToSend;
dataToSend.reserve(m_server.m_topics.size());
for (auto&& topic : m_server.m_topics) {
bool removed = false;
if (replace) {
@@ -687,11 +692,15 @@ void ClientData4Base::ClientSubscribe(int64_t subuid,
// send last value
if (added && !sub->options.topicsOnly && !wasSubscribedValue &&
topic->lastValue) {
DEBUG4("send last value for {} to client {}", topic->name, m_id);
SendValue(topic.get(), topic->lastValue, kSendAll);
dataToSend.emplace_back(topic.get());
}
}
for (auto topic : dataToSend) {
DEBUG4("send last value for {} to client {}", topic->name, m_id);
SendValue(topic, topic->lastValue, kSendAll);
}
// update meta data
UpdateMetaClientSub();