Skip to content

Commit

Permalink
Client side unary communication performance improvements (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
CPattar-NI authored Jan 24, 2024
1 parent bd323d9 commit 0020685
Show file tree
Hide file tree
Showing 18 changed files with 925 additions and 624 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ add_library(labview_grpc_server SHARED
src/grpc_server.cc
src/lv_interop.cc
src/lv_message.cc
src/lv_message_efficient.cc
src/lv_message_value.cc
src/lv_proto_server_reflection_plugin.cc
src/lv_proto_server_reflection_service.cc
Expand Down
Binary file modified labview source/gRPC lv Support/Client API/Client Unary Call.vim
Binary file not shown.
60 changes: 30 additions & 30 deletions src/cluster_copier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ namespace grpc_labview {
{
if (metadata->isRepeated)
{
auto repeatedString = static_cast<const LVRepeatedStringMessageValue&>(*value);
auto repeatedString = static_cast<const LVRepeatedMessageValue<std::string>&>(*value);
if (repeatedString._value.size() != 0)
{
NumericArrayResize(0x08, 1, start, repeatedString._value.size());
Expand Down Expand Up @@ -356,7 +356,7 @@ namespace grpc_labview {
{
if (metadata->isRepeated)
{
auto repeatedInt32 = std::static_pointer_cast<LVRepeatedInt32MessageValue>(value);
auto repeatedInt32 = std::static_pointer_cast<LVRepeatedMessageValue<int>>(value);
if (repeatedInt32->_value.size() != 0)
{
NumericArrayResize(0x03, 1, start, repeatedInt32->_value.size());
Expand All @@ -368,7 +368,7 @@ namespace grpc_labview {
}
else
{
*(int*)start = ((LVInt32MessageValue*)value.get())->_value;
*(int*)start = ((LVVariableMessageValue<int>*)value.get())->_value;
}
}

Expand All @@ -378,7 +378,7 @@ namespace grpc_labview {
{
if (metadata->isRepeated)
{
auto repeatedUInt32 = std::static_pointer_cast<LVRepeatedUInt32MessageValue>(value);
auto repeatedUInt32 = std::static_pointer_cast<LVRepeatedMessageValue<uint32_t>>(value);
if (repeatedUInt32->_value.size() != 0)
{
NumericArrayResize(0x03, 1, start, repeatedUInt32->_value.size());
Expand All @@ -390,7 +390,7 @@ namespace grpc_labview {
}
else
{
*(int*)start = ((LVUInt32MessageValue*)value.get())->_value;
*(int*)start = ((LVVariableMessageValue<uint32_t>*)value.get())->_value;
}
}

Expand Down Expand Up @@ -435,7 +435,7 @@ namespace grpc_labview {
{
if (metadata->isRepeated)
{
auto repeatedInt64 = std::static_pointer_cast<LVRepeatedInt64MessageValue>(value);
auto repeatedInt64 = std::static_pointer_cast<LVRepeatedMessageValue<int64_t>>(value);
if (repeatedInt64->_value.size() != 0)
{
NumericArrayResize(0x04, 1, start, repeatedInt64->_value.size());
Expand All @@ -447,7 +447,7 @@ namespace grpc_labview {
}
else
{
*(int64_t*)start = ((LVInt64MessageValue*)value.get())->_value;
*(int64_t*)start = ((LVVariableMessageValue<int64_t>*)value.get())->_value;
}
}

Expand All @@ -457,7 +457,7 @@ namespace grpc_labview {
{
if (metadata->isRepeated)
{
auto repeatedUInt64 = std::static_pointer_cast<LVRepeatedUInt64MessageValue>(value);
auto repeatedUInt64 = std::static_pointer_cast<LVRepeatedMessageValue<uint64_t>>(value);
if (repeatedUInt64->_value.size() != 0)
{
NumericArrayResize(0x08, 1, start, repeatedUInt64->_value.size());
Expand All @@ -469,7 +469,7 @@ namespace grpc_labview {
}
else
{
*(uint64_t*)start = ((LVUInt64MessageValue*)value.get())->_value;
*(uint64_t*)start = ((LVVariableMessageValue<uint64_t>*)value.get())->_value;
}
}

Expand All @@ -479,7 +479,7 @@ namespace grpc_labview {
{
if (metadata->isRepeated)
{
auto repeatedBoolean = std::static_pointer_cast<LVRepeatedBooleanMessageValue>(value);
auto repeatedBoolean = std::static_pointer_cast<LVRepeatedMessageValue<bool>>(value);
if (repeatedBoolean->_value.size() != 0)
{
NumericArrayResize(0x01, 1, start, repeatedBoolean->_value.size());
Expand All @@ -491,7 +491,7 @@ namespace grpc_labview {
}
else
{
*(bool*)start = ((LVBooleanMessageValue*)value.get())->_value;
*(bool*)start = ((LVVariableMessageValue<bool>*)value.get())->_value;
}
}

Expand All @@ -501,7 +501,7 @@ namespace grpc_labview {
{
if (metadata->isRepeated)
{
auto repeatedDouble = std::static_pointer_cast<LVRepeatedDoubleMessageValue>(value);
auto repeatedDouble = std::static_pointer_cast<LVRepeatedMessageValue<double>>(value);
if (repeatedDouble->_value.size() != 0)
{
auto array = *(LV1DArrayHandle*)start;
Expand All @@ -514,7 +514,7 @@ namespace grpc_labview {
}
else
{
*(double*)start = ((LVDoubleMessageValue*)value.get())->_value;
*(double*)start = ((LVVariableMessageValue<double>*)value.get())->_value;
}
}

Expand All @@ -524,7 +524,7 @@ namespace grpc_labview {
{
if (metadata->isRepeated)
{
auto repeatedFloat = std::static_pointer_cast<LVRepeatedFloatMessageValue>(value);
auto repeatedFloat = std::static_pointer_cast<LVRepeatedMessageValue<float>>(value);
if (repeatedFloat->_value.size() != 0)
{
NumericArrayResize(0x03, 1, start, repeatedFloat->_value.size());
Expand All @@ -536,7 +536,7 @@ namespace grpc_labview {
}
else
{
*(float*)start = ((LVFloatMessageValue*)value.get())->_value;
*(float*)start = ((LVVariableMessageValue<float>*)value.get())->_value;
}
}

Expand Down Expand Up @@ -681,7 +681,7 @@ namespace grpc_labview {
auto array = *(LV1DArrayHandle*)start;
if (array && *array && ((*array)->cnt != 0))
{
auto repeatedStringValue = std::make_shared<LVRepeatedStringMessageValue>(metadata->protobufIndex);
auto repeatedStringValue = std::make_shared<LVRepeatedMessageValue<std::string>>(metadata->protobufIndex);
message._values.emplace(metadata->protobufIndex, repeatedStringValue);
auto lvStr = (*array)->bytes<LStrHandle>();
for (int x = 0; x < (*array)->cnt; ++x)
Expand Down Expand Up @@ -717,7 +717,7 @@ namespace grpc_labview {
if (array && *array && ((*array)->cnt != 0))
{
auto count = (*array)->cnt;
auto repeatedValue = std::make_shared<LVRepeatedBooleanMessageValue>(metadata->protobufIndex);
auto repeatedValue = std::make_shared<LVRepeatedMessageValue<bool>>(metadata->protobufIndex);
message._values.emplace(metadata->protobufIndex, repeatedValue);
auto data = (*array)->bytes<bool>();
repeatedValue->_value.Reserve(count);
Expand All @@ -727,7 +727,7 @@ namespace grpc_labview {
}
else
{
auto value = std::make_shared<LVBooleanMessageValue>(metadata->protobufIndex, *(bool*)start);
auto value = std::make_shared<LVVariableMessageValue<bool>>(metadata->protobufIndex, *(bool*)start);
message._values.emplace(metadata->protobufIndex, value);
}
}
Expand All @@ -742,7 +742,7 @@ namespace grpc_labview {
if (array && *array && ((*array)->cnt != 0))
{
auto count = (*array)->cnt;
auto repeatedValue = std::make_shared<LVRepeatedInt32MessageValue>(metadata->protobufIndex);
auto repeatedValue = std::make_shared<LVRepeatedMessageValue<int>>(metadata->protobufIndex);
message._values.emplace(metadata->protobufIndex, repeatedValue);
auto data = (*array)->bytes<int32_t>();
repeatedValue->_value.Reserve(count);
Expand All @@ -752,7 +752,7 @@ namespace grpc_labview {
}
else
{
auto value = std::make_shared<LVInt32MessageValue>(metadata->protobufIndex, *(int*)start);
auto value = std::make_shared<LVVariableMessageValue<int>>(metadata->protobufIndex, *(int*)start);
message._values.emplace(metadata->protobufIndex, value);
}
}
Expand All @@ -767,7 +767,7 @@ namespace grpc_labview {
if (array && *array && ((*array)->cnt != 0))
{
auto count = (*array)->cnt;
auto repeatedValue = std::make_shared<LVRepeatedUInt32MessageValue>(metadata->protobufIndex);
auto repeatedValue = std::make_shared<LVRepeatedMessageValue<uint32_t>>(metadata->protobufIndex);
message._values.emplace(metadata->protobufIndex, repeatedValue);
auto data = (*array)->bytes<uint32_t>();
repeatedValue->_value.Reserve(count);
Expand All @@ -777,7 +777,7 @@ namespace grpc_labview {
}
else
{
auto value = std::make_shared<LVUInt32MessageValue>(metadata->protobufIndex, *(uint32_t*)start);
auto value = std::make_shared<LVVariableMessageValue<uint32_t>>(metadata->protobufIndex, *(uint32_t*)start);
message._values.emplace(metadata->protobufIndex, value);
}
}
Expand Down Expand Up @@ -833,7 +833,7 @@ namespace grpc_labview {
if (array && *array && ((*array)->cnt != 0))
{
auto count = (*array)->cnt;
auto repeatedValue = std::make_shared<LVRepeatedInt64MessageValue>(metadata->protobufIndex);
auto repeatedValue = std::make_shared<LVRepeatedMessageValue<int64_t>>(metadata->protobufIndex);
message._values.emplace(metadata->protobufIndex, repeatedValue);
auto data = (*array)->bytes<int64_t>();
repeatedValue->_value.Reserve(count);
Expand All @@ -843,7 +843,7 @@ namespace grpc_labview {
}
else
{
auto value = std::make_shared<LVInt64MessageValue>(metadata->protobufIndex, *(int64_t*)start);
auto value = std::make_shared<LVVariableMessageValue<int64_t>>(metadata->protobufIndex, *(int64_t*)start);
message._values.emplace(metadata->protobufIndex, value);
}
}
Expand All @@ -858,7 +858,7 @@ namespace grpc_labview {
if (array && *array && ((*array)->cnt != 0))
{
auto count = (*array)->cnt;
auto repeatedValue = std::make_shared<LVRepeatedUInt64MessageValue>(metadata->protobufIndex);
auto repeatedValue = std::make_shared<LVRepeatedMessageValue<uint64_t>>(metadata->protobufIndex);
message._values.emplace(metadata->protobufIndex, repeatedValue);
auto data = (*array)->bytes<uint64_t>();
repeatedValue->_value.Reserve(count);
Expand All @@ -868,7 +868,7 @@ namespace grpc_labview {
}
else
{
auto value = std::make_shared<LVUInt64MessageValue>(metadata->protobufIndex, *(uint64_t*)start);
auto value = std::make_shared<LVVariableMessageValue<uint64_t>>(metadata->protobufIndex, *(uint64_t*)start);
message._values.emplace(metadata->protobufIndex, value);
}
}
Expand All @@ -883,7 +883,7 @@ namespace grpc_labview {
if (array && *array && ((*array)->cnt != 0))
{
auto count = (*array)->cnt;
auto repeatedValue = std::make_shared<LVRepeatedDoubleMessageValue>(metadata->protobufIndex);
auto repeatedValue = std::make_shared<LVRepeatedMessageValue<double>>(metadata->protobufIndex);
message._values.emplace(metadata->protobufIndex, repeatedValue);
auto data = (*array)->bytes<double>();
repeatedValue->_value.Reserve(count);
Expand All @@ -893,7 +893,7 @@ namespace grpc_labview {
}
else
{
auto value = std::make_shared<LVDoubleMessageValue>(metadata->protobufIndex, *(double*)start);
auto value = std::make_shared<LVVariableMessageValue<double>>(metadata->protobufIndex, *(double*)start);
message._values.emplace(metadata->protobufIndex, value);
}
}
Expand All @@ -908,7 +908,7 @@ namespace grpc_labview {
if (array && *array && ((*array)->cnt != 0))
{
auto count = (*array)->cnt;
auto repeatedValue = std::make_shared<LVRepeatedFloatMessageValue>(metadata->protobufIndex);
auto repeatedValue = std::make_shared<LVRepeatedMessageValue<float>>(metadata->protobufIndex);
message._values.emplace(metadata->protobufIndex, repeatedValue);
auto data = (*array)->bytes<float>();
repeatedValue->_value.Reserve(count);
Expand All @@ -918,7 +918,7 @@ namespace grpc_labview {
}
else
{
auto value = std::make_shared<LVFloatMessageValue>(metadata->protobufIndex, *(float*)start);
auto value = std::make_shared<LVVariableMessageValue<float>>(metadata->protobufIndex, *(float*)start);
message._values.emplace(metadata->protobufIndex, value);
}
}
Expand Down
73 changes: 38 additions & 35 deletions src/feature_toggles.cc
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
#include "feature_toggles.h"
#include <feature_toggles.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>

// Function to read feature configurations from an INI file
void FeatureConfig::readConfigFromFile(const std::string& filePath) {
std::ifstream configFile(filePath);
if (!configFile.is_open()) {
return;
}
namespace grpc_labview {
// Function to read feature configurations from an INI file
void FeatureConfig::readConfigFromFile(const std::string& filePath) {
std::ifstream configFile(filePath);
if (!configFile.is_open()) {
return;
}

std::string line;
std::string currentSection; // For handling INI sections
std::string line;
std::string currentSection; // For handling INI sections

while (std::getline(configFile, line)) {
// Trim leading and trailing whitespaces
line.erase(line.find_last_not_of(" \t") + 1);
line.erase(0, line.find_first_not_of(" \t"));
while (std::getline(configFile, line)) {
// Trim leading and trailing whitespaces
line.erase(line.find_last_not_of(" \t") + 1);
line.erase(0, line.find_first_not_of(" \t"));

// Skip comments and empty lines
if (line.empty() || line[0] == ';') {
continue;
}
// Skip comments and empty lines
if (line.empty() || line[0] == ';') {
continue;
}

// Check for section header
if (line[0] == '[' && line[line.length() - 1] == ']') {
currentSection = line.substr(1, line.length() - 2);
} else {
// Parse key-value pairs
std::istringstream iss(line);
std::string key, value;
if (std::getline(iss, key, '=') && std::getline(iss, value)) {
// Append section name to key for uniqueness
std::string fullKey = currentSection.empty() ? key : currentSection + "_" + key;
featureFlags[fullKey] = (value == "true");
// Check for section header
if (line[0] == '[' && line[line.length() - 1] == ']') {
currentSection = line.substr(1, line.length() - 2);
}
else {
// Parse key-value pairs
std::istringstream iss(line);
std::string key, value;
if (std::getline(iss, key, '=') && std::getline(iss, value)) {
// Append section name to key for uniqueness
std::string fullKey = currentSection.empty() ? key : currentSection + "_" + key;
featureFlags[fullKey] = (value == "true");
}
}
}
}

configFile.close();
}
configFile.close();
}

// Function to check if a feature is enabled
bool FeatureConfig::isFeatureEnabled(const std::string& featureName) const {
auto it = featureFlags.find(featureName);
return (it != featureFlags.end()) ? it->second : false;
// Function to check if a feature is enabled
bool FeatureConfig::isFeatureEnabled(const std::string& featureName) const {
auto it = featureFlags.find(featureName);
return (it != featureFlags.end()) ? it->second : false;
}
}
Loading

0 comments on commit 0020685

Please sign in to comment.