Re: [Libreoffice-commits] Try to cut some costs

2017-02-21 Thread Maxim Monastirsky
Hi Stephan,

On Tue, 2017-02-21 at 10:14 +0100, Stephan Bergmann wrote:
> Any numbers that show that these complications of the code are worth
> it?
> 
TBH I don't know that much about profiling, but when I tested just the
GetGlobalAcceleratorConfiguration function, the cpu time I got was
around 30% of what was before. Also it worth mentioning that this
technique also used in other places in the code base, e.g.

http://opengrok.libreoffice.org/xref/core/framework/source/uielement/su
btoolbarcontroller.cxx#199
http://opengrok.libreoffice.org/xref/core/sfx2/source/appl/imagemgr.cxx
#140

when the latter is of exact the same use case.

Are these complications really worth it? I don't have a definite
answer, as I doubt that the difference can be noticed on a modern hw
(unlike GlobalAcceleratorConfiguration that I changed in the other
commit, which was a real problem).

Maxim
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice-commits] Try to cut some costs

2017-02-21 Thread Stephan Bergmann

Any numbers that show that these complications of the code are worth it?

On 02/21/2017 12:54 AM, Maxim Monastirsky wrote:

commit 8f381b47f5493151f06d77453ff5153cd075a68b
Author: Maxim Monastirsky 
Date:   Mon Feb 20 13:01:46 2017 +0200

Try to cut some costs

Change-Id: I0f541a020232960541bccdf970c042cf3303671e

diff --git a/vcl/source/helper/commandinfoprovider.cxx 
b/vcl/source/helper/commandinfoprovider.cxx
index dad5b58..d95ea55 100644
--- a/vcl/source/helper/commandinfoprovider.cxx
+++ b/vcl/source/helper/commandinfoprovider.cxx
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 

 #include 
 #include 
@@ -37,6 +38,48 @@ using namespace css::uno;

 namespace vcl { namespace CommandInfoProvider {

+Reference const GetCommandDescription()
+{
+static WeakReference xWeakRef;
+css::uno::Reference xRef(xWeakRef);
+
+if (!xRef.is())
+{
+xRef = 
frame::theUICommandDescription::get(comphelper::getProcessComponentContext());
+xWeakRef = xRef;
+}
+
+return xRef;
+}
+
+Reference const 
GetModuleConfigurationSupplier()
+{
+static WeakReference xWeakRef;
+css::uno::Reference 
xRef(xWeakRef);
+
+if (!xRef.is())
+{
+xRef = 
ui::theModuleUIConfigurationManagerSupplier::get(comphelper::getProcessComponentContext());
+xWeakRef = xRef;
+}
+
+return xRef;
+}
+
+Reference const 
GetGlobalAcceleratorConfiguration()
+{
+static WeakReference xWeakRef;
+css::uno::Reference xRef(xWeakRef);
+
+if (!xRef.is())
+{
+xRef = 
ui::GlobalAcceleratorConfiguration::create(comphelper::getProcessComponentContext());
+xWeakRef = xRef;
+}
+
+return xRef;
+}
+
 Reference const GetDocumentAcceleratorConfiguration(const 
Reference& rxFrame)
 {
 Reference xController = rxFrame->getController();
@@ -49,8 +92,7 @@ Reference const 
GetDocumentAcceleratorConfigurati
 if (xSupplier.is())
 {
 Reference xConfigurationManager(
-xSupplier->getUIConfigurationManager(),
-UNO_QUERY);
+xSupplier->getUIConfigurationManager());
 if (xConfigurationManager.is())
 {
 return xConfigurationManager->getShortCutManager();
@@ -66,7 +108,7 @@ Reference const 
GetModuleAcceleratorConfiguration
 css::uno::Reference 
curModuleAcceleratorConfiguration;
 try
 {
-Reference xSupplier  = 
ui::theModuleUIConfigurationManagerSupplier::get(comphelper::getProcessComponentContext());
+Reference 
xSupplier(GetModuleConfigurationSupplier());
 Reference xManager (
 
xSupplier->getUIConfigurationManager(GetModuleIdentifier(rxFrame)));
 if (xManager.is())
@@ -80,13 +122,6 @@ Reference const 
GetModuleAcceleratorConfiguration
 return curModuleAcceleratorConfiguration;
 }

-Reference const 
GetGlobalAcceleratorConfiguration()
-{
-// Get the global accelerator configuration.
-return 
ui::GlobalAcceleratorConfiguration::create(comphelper::getProcessComponentContext());
-
-}
-
 vcl::KeyCode AWTKey2VCLKey(const awt::KeyEvent& aAWTKey)
 {
 bool bShift = ((aAWTKey.Modifiers & awt::KeyModifier::SHIFT) == 
awt::KeyModifier::SHIFT );
@@ -132,7 +167,7 @@ bool ResourceHasKey(const OUString& rsResourceName, const 
OUString& rsCommandNam
 {
 if (!rsModuleName.isEmpty())
 {
-Reference xNameAccess  = 
frame::theUICommandDescription::get(comphelper::getProcessComponentContext());
+Reference 
xNameAccess(GetCommandDescription());
 Reference xUICommandLabels;
 if (xNameAccess->getByName(rsModuleName) >>= xUICommandLabels)
 {
@@ -159,7 +194,7 @@ Sequence GetCommandProperties(const 
OUString& rsCommandNam
 {
 if (!rsModuleName.isEmpty())
 {
-Reference xNameAccess  = 
frame::theUICommandDescription::get(comphelper::getProcessComponentContext());
+Reference 
xNameAccess(GetCommandDescription());
 Reference xUICommandLabels;
 if (xNameAccess->getByName(rsModuleName) >>= xUICommandLabels)
 xUICommandLabels->getByName(rsCommandName) >>= aProperties;
@@ -285,7 +320,7 @@ BitmapEx GetBitmapForCommand(const OUString& rsCommandName,
 Reference xSupplier(xModel, 
UNO_QUERY);
 if (xSupplier.is())
 {
-Reference 
xDocUICfgMgr(xSupplier->getUIConfigurationManager(), UNO_QUERY);
+Reference 
xDocUICfgMgr(xSupplier->getUIConfigurationManager());
 Reference 
xDocImgMgr(xDocUICfgMgr->getImageManager(), UNO_QUERY);

 Sequence< Reference > aGraphicSeq;
@@ -305,7 +340,7 @@ BitmapEx GetBitmapForCommand(const OUString& rsCommandName,
 }

 try {
-Reference 
xModuleCfgMgrSupplier(ui::theModuleUIConfigurationManagerSupplier::get(comphelper::getProcessComponentContext()));
+Reference 
xModuleCfgMgrSupplier(GetModuleConf