Skip to content

Comments

Autosave Session (60 seconds timer)#874

Merged
dail8859 merged 3 commits intodail8859:masterfrom
SimoSbara:master
Nov 8, 2025
Merged

Autosave Session (60 seconds timer)#874
dail8859 merged 3 commits intodail8859:masterfrom
SimoSbara:master

Conversation

@SimoSbara
Copy link
Contributor

This is a simple implementation of a QTimer that saves the sessione each 60 seconds.
It could be improved by adding the interval inside the Preferences Dialog.

It fixes #871 and #658

@SimoSbara
Copy link
Contributor Author

SimoSbara commented Oct 4, 2025

The latest commit could fix #845

@dail8859 dail8859 linked an issue Oct 4, 2025 that may be closed by this pull request
@dail8859
Copy link
Owner

dail8859 commented Oct 5, 2025

The good thing about QTimer is it will run the session saving on the main thread. Scintilla is not thread safe. However, that being said it could possibly cause temporary lag spikes backing up the session. Have you tested this at all on having multiple and/or large files opened? I'm curious if there's any indication of when it may start to visually lag the UI and input for the user.

In the end this is by far the safest/easiest.

@SimoSbara
Copy link
Contributor Author

SimoSbara commented Oct 5, 2025

The good thing about QTimer is it will run the session saving on the main thread. Scintilla is not thread safe. However, that being said it could possibly cause temporary lag spikes backing up the session. Have you tested this at all on having multiple and/or large files opened? I'm curious if there's any indication of when it may start to visually lag the UI and input for the user.

In the end this is by far the safest/easiest.

I often use QTimer for doing things (qt graphics, signals to UI in qt quick) from the main thread.
About the lag spikes: yes, it could happen but I think it is unnoticeable in the normal use case. I will test it on a few large files and let you know if it lags a lot.

Another idea could be:

  1. the main thread retrieves the text buffer from Scintilla
  2. the main thread passes the text buffer to another thread that writes on the disk, this avoids the UI to lock for the disk write operation, the main threads needs to pass the memory reference to another thread (very fast).
  3. the main thread continues the execution of UI

This happens only in the "autosave" done by the QTimer. The aboutToClose() could call a slot that saves everything from the main thread.

@dail8859
Copy link
Owner

dail8859 commented Oct 5, 2025

it could happen but I think it is unnoticeable in the normal use case.

Agreed.

Another idea could be:

Ah yes that would prevent accessing the Scintilla editor(s) from multiple threads by grabbing and passing the text to the background thread, rather than the thread using the editor. It could possibly have a memory spike "duplicating" all the files, but that is probably also acceptable. Or it could pass the text buffer one by one rather then all of them at once. Just an implementation difference is all.


Overall I think this is a great and simple first implementation to see how well it works in the real world. No point in over-engineering a solution if it's not need yet.

@SimoSbara SimoSbara requested a review from dail8859 October 19, 2025 13:41
@dail8859 dail8859 merged commit ebabc63 into dail8859:master Nov 8, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

changes are saved only on a clean exit Session restoration only works upon close

3 participants