From 257792225f9e3ab8037c9b5c414443ed999134a0 Mon Sep 17 00:00:00 2001 From: Yulong Wang <7679871+fs-eire@users.noreply.github.com> Date: Mon, 2 Sep 2024 19:01:08 -0700 Subject: [PATCH] revert forceinline for MakeString (#21943) ### Description revert forceinline for MakeString. This change reverts https://github.com/microsoft/onnxruntime/pull/21893. The forceinline was introduced for performance considerations, however it turns out to have some notable binary size increase, which is a concern for some binary size sensitive platforms like Android. I made a few tests locally and found it is not related to whether or not have used the template struct `if_char_array_make_ptr_t` trick. So I have to revert this back. --- include/onnxruntime/core/common/make_string.h | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/include/onnxruntime/core/common/make_string.h b/include/onnxruntime/core/common/make_string.h index c47e6cc35e488..6148ef63e7264 100644 --- a/include/onnxruntime/core/common/make_string.h +++ b/include/onnxruntime/core/common/make_string.h @@ -19,36 +19,43 @@ #include #include +#include #include -#include "core/util/force_inline.h" - namespace onnxruntime { namespace detail { -ORT_FORCEINLINE void MakeStringImpl(std::ostringstream& /*ss*/) noexcept { +inline void MakeStringImpl(std::ostringstream& /*ss*/) noexcept { } template -ORT_FORCEINLINE void MakeStringImpl(std::ostringstream& ss, const T& t) noexcept { +inline void MakeStringImpl(std::ostringstream& ss, const T& t) noexcept { ss << t; } template -ORT_FORCEINLINE void MakeStringImpl(std::ostringstream& ss, const T& t, const Args&... args) noexcept { +inline void MakeStringImpl(std::ostringstream& ss, const T& t, const Args&... args) noexcept { MakeStringImpl(ss, t); MakeStringImpl(ss, args...); } // see MakeString comments for explanation of why this is necessary template -ORT_FORCEINLINE std::string MakeStringImpl(const Args&... args) noexcept { +inline std::string MakeStringImpl(const Args&... args) noexcept { std::ostringstream ss; MakeStringImpl(ss, args...); return ss.str(); } +template +inline std::string MakeStringWithClassicLocaleImpl(const Args&... args) noexcept { + std::ostringstream ss; + ss.imbue(std::locale::classic()); + MakeStringImpl(ss, args...); + return ss.str(); +} + // // Infrastructure to convert char[n] to char* to reduce binary size // @@ -80,7 +87,7 @@ using if_char_array_make_ptr_t = typename if_char_array_make_ptr::type; * This version uses the current locale. */ template -ORT_FORCEINLINE std::string MakeString(const Args&... args) { +inline std::string MakeString(const Args&... args) { // We need to update the types from the MakeString template instantiation to decay any char[n] to char*. // e.g. MakeString("in", "out") goes from MakeString to MakeStringImpl // so that MakeString("out", "in") will also match MakeStringImpl instead of requiring @@ -100,28 +107,25 @@ ORT_FORCEINLINE std::string MakeString(const Args&... args) { * This version uses std::locale::classic(). */ template -ORT_FORCEINLINE std::string MakeStringWithClassicLocale(const Args&... args) { - std::ostringstream ss; - ss.imbue(std::locale::classic()); - detail::MakeStringImpl(ss, args...); - return ss.str(); +inline std::string MakeStringWithClassicLocale(const Args&... args) { + return detail::MakeStringWithClassicLocaleImpl(detail::if_char_array_make_ptr_t(args)...); } // MakeString versions for already-a-string types. -ORT_FORCEINLINE std::string MakeString(const std::string& str) { +inline std::string MakeString(const std::string& str) { return str; } -ORT_FORCEINLINE std::string MakeString(const char* cstr) { +inline std::string MakeString(const char* cstr) { return cstr; } -ORT_FORCEINLINE std::string MakeStringWithClassicLocale(const std::string& str) { +inline std::string MakeStringWithClassicLocale(const std::string& str) { return str; } -ORT_FORCEINLINE std::string MakeStringWithClassicLocale(const char* cstr) { +inline std::string MakeStringWithClassicLocale(const char* cstr) { return cstr; }