From ecf708e90d96d5a72491e40fa679c47e66eebd49 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 8 Nov 2019 12:45:26 +0100 Subject: Avoid repeated calls cppu::detail::loadModule -> osl_getModuleURLFromAddress ...where the latter are reportedly expensive. Both "tdf#121740 related, cache external mapping in cppu::loadExternal" and "tdf#121740 add cache to win osl_getModuleURLFromAddress" attempted to reduce the costs observed when loading one specific document by introducing caches below cppu::detail::loadModule's call to osl::Module::loadRelative. On the other hand, this change reduces the number of calls to osl_getModuleURLFromAddress by computing the base URI in cppu::detail::loadModule only once. For my local Linux --enable-dbgutil build, for `instdir/program/soffice '109340 class14.ppt'` and then exiting LO again (with the document attached at ), this reduces the number of calls to osl_getModuleURLFromAddress from 3775 to 22. (Many of those calls originated from cppu::getCaughtException or cppu::throwException, as in osl_getModuleURLFromAddress osl_getModuleURLFromFunctionAddress osl::Module::getUrlFromAddress osl_loadModuleRelative osl::Module::loadRelative cppu::detail::loadModule cppu::loadModule cppu::loadExternalMapping uno_getMapping com::sun::star::uno::Mapping::Mapping cppu::throwException .) Unfortunately, this needs to duplicate functionality from osl_loadModuleRelative (sal/osl/all/loadmodulerelative.cxx) somewhat, as the stable SAL interface only offers functionality to load relative to a given function, not relative to a given base URI. (And extending the stable SAL interface for this one use is not worth the maintenance costs.) Change-Id: Ib58814136d11c67d1419b0224d12e30bb710e613 Reviewed-on: https://gerrit.libreoffice.org/82290 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- cppu/source/uno/loadmodule.cxx | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/cppu/source/uno/loadmodule.cxx b/cppu/source/uno/loadmodule.cxx index 9e970b754536..359227b24206 100644 --- a/cppu/source/uno/loadmodule.cxx +++ b/cppu/source/uno/loadmodule.cxx @@ -20,10 +20,15 @@ #include +#include + #include #include +#include +#include #include #include +#include #include "loadmodule.hxx" @@ -32,14 +37,34 @@ namespace cppu { namespace detail { #ifndef DISABLE_DYNLOADING bool loadModule(osl::Module& rModule, OUString const & name) { + static OUString base = [] { + OUString url; + if (!osl::Module::getUrlFromAddress( + reinterpret_cast(&loadModule), url)) + { + SAL_WARN("cppu", "osl::Module::getUrlFromAddress failed"); + return OUString(); + } + assert(!url.isEmpty()); + return url; + }(); + if (base.isEmpty()) { + SAL_INFO("cppu", "osl::Module::getUrlFromAddress had failed"); + return false; + } OUString b = #if defined SAL_DLLPREFIX SAL_DLLPREFIX + #endif name + SAL_DLLEXTENSION; - return rModule.loadRelative( - reinterpret_cast< oslGenericFunction >(&loadModule), + try { + b = rtl::Uri::convertRelToAbs(base, b); + } catch (rtl::MalformedUriException & e) { + SAL_INFO("cppu", "rtl::MalformedUriException <" << e.getMessage() << ">"); + return false; + } + return rModule.load( b, SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_LAZY); } -- cgit