From 7ad76f978f67669ae6e37fa180517a3cc7dca01f Mon Sep 17 00:00:00 2001 From: Michael Poggy Date: Tue, 28 Jan 2025 09:10:54 -0800 Subject: [PATCH] Avoid copying FB303's get(Regex|Selected)Counters result map in BaseService.h Summary: ## Context I was glancing at the [Container Copies](https://www.internalfb.com/intern/unidash/dashboard/bad_patterns/container_copies/?dimensional_context_300674582190283=%7B%22macros%22%3A[]%2C%22operators%22%3A[]%2C%22movingAggregation%22%3A%22DEFAULT%22%2C%22granularity%22%3A%22DEFAULT%22%2C%22limit%22%3A5%7D) Bad Patterns dashboard and this one stood out to me. This is a locally defined `std::map` that we don't seem to use beyond the `result` call where I've added `std::move`. Similar optimizations were performed in D55817430, where the underlying callback was made to take arguments by value. This must have been missed. Seems like a small ([~14kW](https://fburl.com/scuba/strobelight_services/whv43t10)), but easy win. Reviewed By: yfeldblum Differential Revision: D68642453 fbshipit-source-id: 3d7687ae0d2c9a57304ea86c7b03538ee380f957 --- fb303/BaseService.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fb303/BaseService.h b/fb303/BaseService.h index 732a9e3f4..289ba271e 100644 --- a/fb303/BaseService.h +++ b/fb303/BaseService.h @@ -233,7 +233,7 @@ class BaseService : virtual public cpp2::BaseServiceSvIf { } addCountersAvailableToResponse(reqCtx, numAvailable); } - callback_->result(res); + callback_->result(std::move(res)); } catch (...) { callback_->exception(std::current_exception()); } @@ -273,7 +273,7 @@ class BaseService : virtual public cpp2::BaseServiceSvIf { } addCountersAvailableToResponse(reqCtx, numAvailable); } - callback_->result(res); + callback_->result(std::move(res)); } catch (...) { callback_->exception(std::current_exception()); } @@ -313,7 +313,7 @@ class BaseService : virtual public cpp2::BaseServiceSvIf { } addCountersAvailableToResponse(reqCtx, numAvailable); } - callback_->result(res); + callback_->result(std::move(res)); } catch (...) { callback_->exception(std::current_exception()); }