View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0017931 | Scribus | Scripter | public | 2026-08-19 15:47 | 2026-11-05 10:14 |
| Reporter | flagsoft | Assigned To | |||
| Priority | normal | Severity | major | Reproducibility | always |
| Status | new | Resolution | open | ||
| Product Version | 1.7.4.svn | ||||
| Summary | 0017931: Scribus Python scripts run 2 times slower every time if called again | ||||
| Description | It doubles the time to execute every time you run a Scribus Python script again. | ||||
| Steps To Reproduce | 1. Start Scribus 2. Run your Python Script 3. Run your Python Script again (about 2 times slower then before 2.!) 4. Run your Python Script again (about 2 times slower then before 3.!) etc. It doubles the time to execute every time you run a Scribus Python script again. Tested with 1.6.6 (Download, stable) 1.6.7.svn (compiled) 1.7.4.svn (compiled) Always the same behaviour. So before optimizing your script for speed, just re-start Scribus again... but this is no solution. Wonder what this is, or is there a "reset" python Script that we can / should call at the beginning of any Script? | ||||
| Tags | undo | ||||
| Patch | No | ||||
|
|
Can you please provide a script that has some timing measurement and can be used to replicate the issue? |
|
|
## 2026-08aug-19
## twice-as-slow-every-time.py
## Scribus 1.6.6 script
##
import sys
import gc
## -- for debug time
import time
from datetime import datetime
try:
import scribus
except ImportError:
print('This script must be run from inside Scribus')
sys.exit()
def main():
now = datetime.now()
print("- BEGIN:", now.strftime("%Y-%m-%d %H:%M:%S") )
DEBUG_start = time.time()
scribus.setRedraw(False)
## -- remove textframe if they exist
for tmp_num in range(1, 20):
if scribus.objectExists('_textframe_'+str(tmp_num)):
scribus.deleteObject('_textframe_'+str(tmp_num))
print("- removed existing textframe number:", tmp_num)
## -- create textframe
for y in range(1, 20):
offset_y = y*10;
scribus.createText(20, 4 + offset_y, 90, 6, '_textframe_'+str(y))
scribus.setText('Text'+str(y), '_textframe_'+str(y))
#scribus.insertText(str(y), -1)
#print(y)
scribus.setRedraw(True)
now2 = datetime.now()
print("- END:", now2.strftime("%Y-%m-%d %H:%M:%S") )
DEBUG_end = time.time()
print("- Execution time [seconds]: ", DEBUG_end - DEBUG_start)
if __name__ == "__main__":
main()
## Explicitly force Python garbage collection at the end of the run
gc.collect() ## does not help, scrpit slows down two times every tine it gets called again
|
|
|
Has anyone tested this? What can we do about it? Seems to be a problem on all versions of Scribus. |
|
|
I've now tried it out. And I've found out will surprise you. At first, yes, I can replicate. But then, OK, it's deleting and adding again the same frame. And the execution time somehow grows. It does not really double, but it grows noticeably. What about undoing before the next run? Oh, yes, now it's faster again. Not as fast as the beginning, but faster again. Then slower again. Oh, and if it is the undo that gets slower and slower? In the Document Setup I've turned off the undo and: the time does not grow anymore. Questions:
|
|
|
Thanks for testing. And, yes, it is in deed the UNDO system. But I think it's implemented the wrong way, maybe? It can't be that slow. If Scribus fix this, it will be a huge update in performance for the end user. If there is a Scribus Python function to temporary disable and enable UNDO it would be great. Something like that: - scribus.useUndo(False) - scribus.useUndo(True) - scribus.useUndo(4) Of, as it's per document: - scribus.documentUndo(False) - scribus.documentUndo(True) - scribus.documentUndo(4) |
|
|
indeed - can one edit posts here? |
|
|
I've looked at this over the last week on and off. I have committed a couple of changes but mostly fixes and not things that will speed this up unfortunately. |
|
|
Can we have at least the Python functions to disable/enable Undo? f there is a Scribus Python function to temporary disable and enable UNDO it would be great. Something like that: - scribus.useUndo(False) - scribus.useUndo(True) - scribus.useUndo(4) Of, as it's per document: - scribus.documentUndo(False) - scribus.documentUndo(True) - scribus.documentUndo(4) |
|
|
Add this to cmdmisc.h ``` /*! docstring */ PyDoc_STRVAR(scribus_disableundo__doc__, QT_TR_NOOP("disableUndo()\n\ \n\ Switches the undo system off. Actions performed afterwards are not recorded,\n\ which speeds up scripts that make many changes (e.g. in loops).\n\ Call enableUndo() when done. Does not clear the existing undo stack.\n\ ")); /*! Switches undo off. */ PyObject *scribus_disableundo(PyObject * /*self*/); /*! docstring */ PyDoc_STRVAR(scribus_enableundo__doc__, QT_TR_NOOP("enableUndo()\n\ \n\ Switches the undo system back on after disableUndo().\n\ ")); /*! Switches undo on. */ PyObject *scribus_enableundo(PyObject * /*self*/); /*! docstring */ PyDoc_STRVAR(scribus_isundoenabled__doc__, QT_TR_NOOP("isUndoEnabled() -> bool\n\ \n\ Returns True if the undo system is currently recording actions.\n\ ")); /*! Returns the undo state. */ PyObject *scribus_isundoenabled(PyObject * /*self*/); ``` And this to cmdmisc.cpp ``` #include "undomanager.h" PyObject *scribus_disableundo(PyObject * /*self*/) { UndoManager::instance()->setUndoEnabled(false); Py_RETURN_NONE; } PyObject *scribus_enableundo(PyObject * /*self*/) { UndoManager::instance()->setUndoEnabled(true); Py_RETURN_NONE; } PyObject *scribus_isundoenabled(PyObject * /*self*/) { return PyBool_FromLong(UndoManager::instance()->undoEnabled() ? 1 : 0); } ``` Test: ``` import scribus scribus.disableUndo() try: for i in range(1000): scribus.createRect(10, 10 + i, 50, 5) finally: scribus.enableUndo() ``` |
|
|
The patch you've also attached to the new ticket 0018064 probably mitigates the issue. But the real solution would be to have a way to optionally tell Scribus to record all the steps in one single undo step (and make sure that it's fast enough), not to disable the undo. |
|
|
"to optionally tell Scribus to record all the steps in one single undo step" Good idea. But I have no idea how to do that or if it's even technically possible to do that. As far as I can tell disableUndo and enableUndo works. At least on 1.6.8.snv (checkout from 04. NOV. 2026) |
|
|
We have undo transactions that group undo steps into one group. That’s not the same as a single undo step as such but it’s the mechanism required. We can implement cresting a transaction via scripter. |
|
|
Yes, a first step to solve this ticket is probably to allow the scripter to start and stop transactions. There is one thing that we might need to take care of: when the script finishes (in any way... but a hard crash... like pulling the cord), all the transactions opened by the Scripter must be (automatically) closed. The best way to do that is to make sure that transactions can be started with the <kbd>with</kbd> statement (like when opening files or generally managing resources). Of course, if using a transaction is still dead slow, then we will need to figure out how to speed up the whole undo system, but it will be already a step in the right direction. Also, Buttar's efforts to "clean up" the steps recorded in the undo might also help here. |
|
|
Yes, Scribus has transactions for this (UndoManager::beginTransaction() and UndoTransaction::commit()), which the GUI already uses for compound actions like “duplicate multiple”. scribus/undomanager.h. BUT: A transaction still records every individual action internally and only merges them into one entry on commit. It gives you the single undo step but is not as fast as disableUndo(). For speed and loops: use disableUndo() If speed is the main goal, keep disableUndo() for big loops. Combining both: - disableUndo() is the right tool for huge loops when you don’t need undo at all. - Use beginUndoGroup() when the user should be able to revert the script’s work with one Ctrl+Z. Both can coexist, but while undo is disabled nothing is recorded, so the group ends up empty. More robust disableUndo() version, tested, seems to work. To make the Python API robust, keep your own script-level depth counter: ``` cpp namespace { int s_scriptUndoDisableDepth = 0; } PyObject *scribus_disableundo(PyObject * /*self*/) { UndoManager::instance()->setUndoEnabled(false); ++s_scriptUndoDisableDepth; Py_RETURN_NONE; } PyObject *scribus_enableundo(PyObject * /*self*/) { if (s_scriptUndoDisableDepth > 0) { --s_scriptUndoDisableDepth; UndoManager::instance()->setUndoEnabled(true); } Py_RETURN_NONE; } This way a script can only undo its own disableUndo() calls. This restores the counter even if the script crashed. ``` |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-08-19 15:47 | flagsoft | New Issue | |
| 2026-08-19 15:58 | ale | Note Added: 0054232 | |
| 2026-08-19 18:25 | flagsoft | Note Added: 0054236 | |
| 2026-08-23 14:11 | flagsoft | Note Added: 0054293 | |
| 2026-08-25 19:55 | jghali | Priority | high => normal |
| 2026-08-26 18:37 | ale | Note Edited: 0054236 | |
| 2026-08-26 19:07 | ale | Note Added: 0054310 | |
| 2026-08-26 19:08 | ale | Tag Attached: undo | |
| 2026-08-27 17:40 | flagsoft | Note Added: 0054346 | |
| 2026-08-27 17:41 | flagsoft | Note Added: 0054347 | |
| 2026-08-27 20:42 | cbradney | Note Added: 0054348 | |
| 2026-08-29 17:11 | flagsoft | Note Added: 0054374 | |
| 2026-11-04 16:44 | flagsoft | Note Added: 0054648 | |
| 2026-11-05 08:40 | ale | Note Added: 0054654 | |
| 2026-11-05 08:51 | flagsoft | Note Added: 0054655 | |
| 2026-11-05 09:09 | cbradney | Note Added: 0054656 | |
| 2026-11-05 09:28 | ale | Note Added: 0054657 | |
| 2026-11-05 10:14 | flagsoft | Note Added: 0054658 |