summaryrefslogtreecommitdiff
path: root/librelogo
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2022-12-02 18:06:17 +0100
committerLászló Németh <nemeth@numbertext.org>2022-12-05 16:15:20 +0000
commite50f0f7342c5618196507771e5f4eb79147477b9 (patch)
tree4b8edf129b07bf5dc3cc1b974a1a68ddf9b59822 /librelogo
parent43570f5752b31e11a7f21d5e694737e9fcb3bf19 (diff)
tdf#105575 LibreLogo: speed up by lock (re)paint
Speed up program execution by default partial locking of repaint and custom locking of paint, using UNO lockControllers(). – Default: speed up LABEL and TEXT by locking their repaint during the various text operations, i.e. setting size and text portion formatting changes were visible, and slow. Locking while manipulating a shape was suggested by Noel Grandin. – Custom: SLEEP command with negative argument calls lockControllers(), SLEEP command with not negative argument (and program termination) call unlockControllers(), so it's possible to lock program parts to speed up program execution e.g. 3-4 times or more. For example: ; lock paint until program termination SLEEP -1 program or ; lock until SLEEP 0 SLEEP -1 commands_without_paint SLEEP 0 ; unlock a single level and paint/repaint everything – Add __get_time__() command to get the elapsed time from program start for profiling. Add unit tests. Note: custom locking with SLEEP has known problems: not connected lines, bad position of arc/pie, non-working CLEARSCREEN. Note: The reported code is more than 32 times faster (4 sec vs 2.2 min) with custom locking, also using the commented line to show not only the result with 400 circle shapes, but the partial result with 100, 200 and 300 shapes, too: SLEEP -1 REPEAT 400 [ CIRCLE 10 + REPCOUNT/10 FORWARD 5 + REPCOUNT/10 LEFT 10 ] ; IF REPCOUNT % 100 == 0 [ SLEEP 0 SLEEP -1 ] ; to show partial result SLEEP 0 PRINT __get_time__() Change-Id: I51f71b0143178e6d35ecced92a59525184392d17 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143640 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'librelogo')
-rw-r--r--librelogo/source/LibreLogo/LibreLogo.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/librelogo/source/LibreLogo/LibreLogo.py b/librelogo/source/LibreLogo/LibreLogo.py
index 562095a15383..ccd504eba021 100644
--- a/librelogo/source/LibreLogo/LibreLogo.py
+++ b/librelogo/source/LibreLogo/LibreLogo.py
@@ -479,6 +479,9 @@ def __translate__(arg = None):
selection.getStart().BreakType = 4
__dispatcher__(".uno:ZoomPage")
+def __get_time__():
+ return __time__.process_time() - _.start_time
+
class LogoProgram(threading.Thread):
def __init__(self, code):
self.code = code
@@ -535,7 +538,10 @@ class LogoProgram(threading.Thread):
parent = _.doc.CurrentController.Frame.ContainerWindow
MessageBox(parent, "Document objects with%s script events" % [" possible", ""][secid-1], "LibreLogo program can't start", "errorbox")
else:
+ _.start_time = __time__.process_time()
exec(self.code)
+ while _.doc.hasControllersLocked():
+ _.doc.unlockControllers()
if _.origcursor[0] and _.origcursor[1]:
__dispatcher__(".uno:Escape")
try:
@@ -544,6 +550,8 @@ class LogoProgram(threading.Thread):
_.doc.CurrentController.getViewCursor().gotoRange(_.origcursor[0].getStart(), False)
except Exception as e:
try:
+ while _.doc.hasControllersLocked():
+ _.doc.unlockControllers()
TRACEPATTERN = '"<string>", line '
message = traceback.format_exc()
l = re.findall(TRACEPATTERN + '[0-9]+', message)
@@ -834,6 +842,8 @@ def stop(arg=None):
global __halt__
with __lock__:
__halt__ = True
+ while _.doc.hasControllersLocked():
+ _.doc.unlockControllers()
return None
def home(arg=None):
@@ -1401,6 +1411,7 @@ def __get_HTML_format__(orig_st):
def text(shape, orig_st):
if shape:
+ _.doc.lockControllers()
# analyse HTML
st, formatting, extra_data = __get_HTML_format__(orig_st)
shape.setString(__string__(st, _.decimal))
@@ -1460,8 +1471,17 @@ def text(shape, orig_st):
prev_format = i
if len(extra_data) > 0:
prev_extra_data = extra_data.pop(0)
+ _.doc.unlockControllers()
def sleep(t):
+ if t < 0:
+ # lock shape repaint, if SLEEP argument is negative
+ _.doc.lockControllers()
+ return
+ else:
+ # otherwise unlock one level
+ if _.doc.hasControllersLocked():
+ _.doc.unlockControllers()
_.time = _.time + t
__removeshape__(__ACTUAL__)
for i in range(int(t/__SLEEP_SLICE_IN_MILLISECONDS__)):