From f0edd074fb6a957b7c40a5135af61654043ed1c2 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Wed, 22 Jul 2020 12:29:55 -0700 Subject: [PATCH] Optimize CreateEnv by not creating the logging manager instance if env instance has already been created. (#4583) * Optimize CreateEnv by not creating the logging manager instance if env instance has already been created. * Move creation of logging mgr inside if block --- onnxruntime/core/session/ort_env.cc | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/onnxruntime/core/session/ort_env.cc b/onnxruntime/core/session/ort_env.cc index 0408eef145ef0..ae150e7035fd5 100644 --- a/onnxruntime/core/session/ort_env.cc +++ b/onnxruntime/core/session/ort_env.cc @@ -37,25 +37,24 @@ OrtEnv* OrtEnv::GetInstance(const OrtEnv::LoggingManagerConstructionInfo& lm_inf onnxruntime::common::Status& status, const OrtThreadingOptions* tp_options) { std::lock_guard lock(m_); - std::unique_ptr lmgr; - std::string name = lm_info.logid; - if (lm_info.logging_function) { - std::unique_ptr logger = onnxruntime::make_unique(lm_info.logging_function, - lm_info.logger_param); - lmgr.reset(new LoggingManager(std::move(logger), - static_cast(lm_info.default_warning_level), - false, - LoggingManager::InstanceType::Default, - &name)); - } else { - lmgr.reset(new LoggingManager(std::unique_ptr{new CLogSink{}}, - static_cast(lm_info.default_warning_level), - false, - LoggingManager::InstanceType::Default, - &name)); - } - if (!p_instance_) { + std::unique_ptr lmgr; + std::string name = lm_info.logid; + if (lm_info.logging_function) { + std::unique_ptr logger = onnxruntime::make_unique(lm_info.logging_function, + lm_info.logger_param); + lmgr.reset(new LoggingManager(std::move(logger), + static_cast(lm_info.default_warning_level), + false, + LoggingManager::InstanceType::Default, + &name)); + } else { + lmgr.reset(new LoggingManager(std::unique_ptr{new CLogSink{}}, + static_cast(lm_info.default_warning_level), + false, + LoggingManager::InstanceType::Default, + &name)); + } std::unique_ptr env; if (!tp_options) { status = onnxruntime::Environment::Create(std::move(lmgr), env); @@ -67,6 +66,7 @@ OrtEnv* OrtEnv::GetInstance(const OrtEnv::LoggingManagerConstructionInfo& lm_inf } p_instance_ = new OrtEnv(std::move(env)); } + ++ref_count_; return p_instance_; }