From 1d60e9bf6bccda153478113c4bc7d8adb197c2ce Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Sat, 14 Sep 2024 10:15:17 +0000 Subject: [PATCH] less copying json --- lib/iq_inference_impl.cc | 18 ++++++------------ lib/iq_inference_impl.h | 5 +---- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/lib/iq_inference_impl.cc b/lib/iq_inference_impl.cc index fcf64475..62cb0725 100644 --- a/lib/iq_inference_impl.cc +++ b/lib/iq_inference_impl.cc @@ -363,15 +363,8 @@ void iq_inference_impl::run_inference_(torchserve_client *client) { output_json["predictions"] = results_json; output_json["metadata"] = metadata_json; - const std::string output_json_str = output_json.dump(); - if (output_json_str.size() < MAX_JSON_SIZE) { - json_result_type output_json_chars; - std::copy(output_json_str.begin(), output_json_str.end(), - output_json_chars.data()); - json_q_.push(output_json_chars); - } else { - d_logger->error("output json size too large"); - } + std::string *output_json_str = new std::string(output_json.dump()); + json_q_.push(output_json_str); delete_output_item_(output_item); } } @@ -466,10 +459,11 @@ void iq_inference_impl::process_tags_(COUNT_T in_first, } void iq_inference_impl::pub_json_() { - json_result_type json; - while (json_q_.pop(json)) { + std::string *output_json_str; + while (json_q_.pop(output_json_str)) { ++predictions_; - message_port_pub(INFERENCE_KEY, string_to_pmt(std::string(json.data()))); + message_port_pub(INFERENCE_KEY, string_to_pmt(*output_json_str)); + delete output_json_str; } } diff --git a/lib/iq_inference_impl.h b/lib/iq_inference_impl.h index 33de594f..11974e96 100644 --- a/lib/iq_inference_impl.h +++ b/lib/iq_inference_impl.h @@ -222,7 +222,6 @@ namespace gr { namespace iqtlabs { const COUNT_T MAX_INFERENCE = 5; -const COUNT_T MAX_JSON_SIZE = 8192; typedef struct output_item { FREQ_T rx_freq; @@ -236,8 +235,6 @@ typedef struct output_item { COUNT_T serial; } output_item_type; -typedef std::array json_result_type; - class iq_inference_impl : public iq_inference, base_impl { private: pmt::pmt_t tag_; @@ -255,7 +252,7 @@ class iq_inference_impl : public iq_inference, base_impl { boost::lockfree::queue> inference_q_; - boost::lockfree::queue> json_q_; boost::shared_ptr io_service_;