Getting list of styles is slow

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
olpa
Posts: 3
Joined: Fri Jan 11, 2013 6:38 am

Getting list of styles is slow

Post 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)
LibreOffice 3 on Linux
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Getting list of styles is slow

Post by B Marcelly »

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
User avatar
karolus
Volunteer
Posts: 1158
Joined: Sat Jul 02, 2011 9:47 am

Re: Getting list of styles is slow

Post 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
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
olpa
Posts: 3
Joined: Fri Jan 11, 2013 6:38 am

Re: Getting list of styles is slow

Post 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.
LibreOffice 3 on Linux
User avatar
karolus
Volunteer
Posts: 1158
Joined: Sat Jul 02, 2011 9:47 am

Re: Getting list of styles is slow

Post 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
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
WarehouseJim
Posts: 3
Joined: Sat Jan 19, 2013 6:25 pm

Re: Getting list of styles is slow

Post 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
LibreOffice 3.6.2.2 on Ubuntu 12.10
olpa
Posts: 3
Joined: Fri Jan 11, 2013 6:38 am

Re: Getting list of styles is slow

Post 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.
LibreOffice 3 on Linux
Post Reply