Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Reduce export/import memory usage.
Kishore Nalland9d6a38226b0
diff --git a/include/http_server.h b/include/http_server.hindex b6465e43..1ced92e7 100644--- a/include/http_server.h+++ b/include/http_server.h@@ -51,7 +51,10 @@ public:bool is_res_start = true;h2o_send_state_t send_state = H2O_SEND_STATE_IN_PROGRESS;- h2o_iovec_t res_body{};++ std::string res_body;+ h2o_iovec_t res_buff;+h2o_iovec_t res_content_type{};int status = 0;const char* reason = nullptr;@@ -64,8 +67,10 @@ public:}}- void set_response(uint32_t status_code, const std::string& content_type, const std::string& body) {- res_body = h2o_strdup(&req->pool, body.c_str(), SIZE_MAX);+ void set_response(uint32_t status_code, const std::string& content_type, std::string& body) {+ std::string().swap(res_body);+ res_body = std::move(body);+ res_buff = h2o_iovec_t{.base = res_body.data(), .len = res_body.size()};if(is_res_start) {res_content_type = h2o_strdup(&req->pool, content_type.c_str(), SIZE_MAX);diff --git a/src/http_server.cpp b/src/http_server.cppindex 6a704153..f72de8da 100644--- a/src/http_server.cpp+++ b/src/http_server.cpp@@ -504,6 +504,9 @@ int HttpServer::catch_all_handler(h2o_handler_t *_h2o_handler, h2o_req_t *req) {);*allocated_generator = custom_gen;+ // ensures that the first response need not wait for previous chunk to be done sending+ response->notify();+//LOG(INFO) << "Init res: " << custom_gen->response << ", ref count: " << custom_gen->response.use_count();if(root_resource == "multi_search") {@@ -632,9 +635,6 @@ int HttpServer::async_req_cb(void *ctx, int is_end_stream) {if(request->first_chunk_aggregate) {request->first_chunk_aggregate = false;-- // ensures that the first response need not wait for previous chunk to be done sending- response->notify();}// default value for last_chunk_aggregate is false@@ -821,7 +821,7 @@ void HttpServer::stream_response(stream_response_state_t& state) {h2o_start_response(req, state.generator);}- h2o_send(req, &state.res_body, 1, H2O_SEND_STATE_FINAL);+ h2o_send(req, &state.res_buff, 1, H2O_SEND_STATE_FINAL);h2o_dispose_request(req);return ;@@ -833,13 +833,13 @@ void HttpServer::stream_response(stream_response_state_t& state) {h2o_start_response(req, state.generator);}- if(state.res_body.len == 0 && state.send_state != H2O_SEND_STATE_FINAL) {+ if(state.res_buff.len == 0 && state.send_state != H2O_SEND_STATE_FINAL) {// without this guard, http streaming will breakstate.generator->proceed(state.generator, req);return;}- h2o_send(req, &state.res_body, 1, state.send_state);+ h2o_send(req, &state.res_buff, 1, state.send_state);//LOG(INFO) << "stream_response after send";}