Page 1 of 1

Getting list of styles is slow

Posted: Fri Jan 11, 2013 7:04 am
by olpa
For me, iterating over the list of paragraph styles is slow:

Code: Select all

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

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)

Re: Getting list of styles is slow

Posted: Fri Jan 11, 2013 9:35 am
by B Marcelly
You are measuring the time to print, not the time of retrieving the styles.

Re: Getting list of styles is slow

Posted: Fri Jan 11, 2013 12:09 pm
by karolus
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

Re: Getting list of styles is slow

Posted: Mon Jan 14, 2013 6:56 am
by olpa
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.

Re: Getting list of styles is slow

Posted: Mon Jan 14, 2013 10:51 am
by karolus
Hallo

'Adapted' means :
copy&paste

Code: Select all

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

Re: Getting list of styles is slow

Posted: Sat Jan 19, 2013 6:31 pm
by WarehouseJim
I also experienced your very slow performance.

This worked for me:

Code: Select all

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/comm ... ccess.html
and
http://www.openoffice.org/api/docs/comm ... ccess.html

Re: Getting list of styles is slow

Posted: Sun Feb 17, 2013 8:30 pm
by olpa
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.