Getting list of styles is slow

Java, C++, C#, Delphi, ??? - Using the UNO bridges

Getting list of styles is slow

Postby olpa » Fri Jan 11, 2013 7:04 am

For me, iterating over the list of paragraph styles is slow:

Code: Select all   Expand viewCollapse view
10.0 seconds for 122 styles


10 seconds? I expect 0 here.

Am I doing something wrong?

// LibreOffice 3.5.4.2, 3.4.2-std-def-alt1 #1 SMP

Code: Select all   Expand viewCollapse view
def print_styles(doc):
  stf = doc.getStyleFamilies()
  pss = stf.getByName('ParagraphStyles')
  n = pss.getCount()
  t_begin = time.time()
  for i in range(n):
    ps = pss.getByIndex(i)
    print ps.getName(), '/', ps.DisplayName
  t_end = time.time()
  print '%s seconds for %s styles' % (round(t_end - t_begin), n)

# setup to call the code above
import uno, os, time
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
document = desktop.loadComponentFromURL(uno.systemPathToFileUrl(os.path.abspath('hello.odt')), '_blank', 0, tuple())
print_styles(document)
LibreOffice 3 on Linux
olpa
 
Posts: 3
Joined: Fri Jan 11, 2013 6:38 am

Re: Getting list of styles is slow

Postby B Marcelly » Fri Jan 11, 2013 9:35 am

You are measuring the time to print, not the time of retrieving the styles.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
B Marcelly
Volunteer
 
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Getting list of styles is slow

Postby karolus » Fri Jan 11, 2013 12:09 pm

Hallo
Executing the (adaptet) Function 'print_styles()' prints [last line]:
0.0135910511017 seconds for 122 styles


Maybe the call through uno:socket...etc. is the Bottleneck ?!

Karolus
AOO4, Libreoffice - 5.1 … 5.3.2.2 on Linux Mint17
User avatar
karolus
Volunteer
 
Posts: 852
Joined: Sat Jul 02, 2011 9:47 am

Re: Getting list of styles is slow

Postby olpa » Mon Jan 14, 2013 6:56 am

You are measuring the time to print, not the time of retrieving the styles.

No, one can neglect "print" here. I did comment it out to check.

Executing the (adaptet) Function 'print_styles()'

What means "adapted"? Have you tried it directly in *Office?

0.0135910511017 seconds for 122 styles

This is what I'd expect. 0.01 seconds instead of 10 seconds.

Maybe the call through uno:socket...etc. is the Bottleneck ?!

Quite possible, and it worries me. I can't believe that socket-communications can be so slow.
LibreOffice 3 on Linux
olpa
 
Posts: 3
Joined: Fri Jan 11, 2013 6:38 am

Re: Getting list of styles is slow

Postby karolus » Mon Jan 14, 2013 10:51 am

Hallo

'Adapted' means :
copy&paste
Code: Select all   Expand viewCollapse view

import time

#...

def print_styles():
    doc = XSCRIPTCONTEXT.getDocument()
    stf = doc.getStyleFamilies()
    pss = stf.getByName('ParagraphStyles')
    n = pss.getCount()
    t_begin = time.time()
    for i in range(n):
        ps = pss.getByIndex(i)
        print '%s / %s' %( ps.getName(), ps.DisplayName )
    t_end = time.time()
    print '%s seconds for %s styles' % (t_end - t_begin, n) 

into some .py -file in path ~user/Scripts/python/..., and execute 'print_styles' from out writer

Karolus
AOO4, Libreoffice - 5.1 … 5.3.2.2 on Linux Mint17
User avatar
karolus
Volunteer
 
Posts: 852
Joined: Sat Jul 02, 2011 9:47 am

Re: Getting list of styles is slow

Postby WarehouseJim » Sat Jan 19, 2013 6:31 pm

I also experienced your very slow performance.

This worked for me:
Code: Select all   Expand viewCollapse view
for a in document.getStyleFamilies().getByName("ParagraphStyles").getElementNames():
   print a


The way I found this was by looking at the interfaces used by the object, which include
http://www.openoffice.org/api/docs/common/ref/com/sun/star/container/XNameAccess.html
and
http://www.openoffice.org/api/docs/common/ref/com/sun/star/container/XIndexAccess.html
LibreOffice 3.6.2.2 on Ubuntu 12.10
WarehouseJim
 
Posts: 3
Joined: Sat Jan 19, 2013 6:25 pm

Re: Getting list of styles is slow

Postby olpa » Sun Feb 17, 2013 8:30 pm

After looking at strace, I suppose that the problem is somewhere in the thread-process synchronization code. Maybe something sets a timeout, but forgets to set a callback. Or maybe something goes to sleep for a minimal amount or time. Unfortunately, I have no possibility to investigate in details.
LibreOffice 3 on Linux
olpa
 
Posts: 3
Joined: Fri Jan 11, 2013 6:38 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest