Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out of memory error, when typing a char with 18k carets (almost the limit of "undo_max_carets": 20000) #5696

Open
njwgh opened this issue Sep 20, 2024 · 8 comments

Comments

@njwgh
Copy link

njwgh commented Sep 20, 2024

I have a file with approx 18,000 lines, max 20 chars in each line
I do Ctrl A to select all lines
Then Shift Ctrl L to put in multiple carets and hit home key to go to start of lines
Then type a character (to insert the character at all caret positions) - takes about 6 seconds
Then hit 'end' key to move caret to end of lines, then insert another character - takes about 22 seconds
When I type the third character I get "out of memory" error
I did try changing undo_max_carets option to 10000 , but that didn't help
SublimeText does each character in 3 seconds
Windows 10

@Alexey-T Alexey-T added the bug label Sep 20, 2024
@Alexey-T
Copy link
Owner

Alexey-T commented Sep 20, 2024

Confirmed on Linux. I Will investigate it soon. Now my notebook's SSD disk is dying and replacing Will be only next week. Im not in the town.

@Alexey-T
Copy link
Owner

Alexey-T commented Sep 20, 2024

I confirm the memory grow (up to 7 Gb for typing at line start with 18k carets) + slow work.
BUT for me - low value of option "undo_max_carets": 2000 HELPS. Ie memory don't grow anymore + work is much faster. 3-5 secs for typing at line start / at line end.
Even app restart is not needed if you change the option. But you must save the user.json if you edit it.

@Alexey-T Alexey-T removed the bug label Sep 20, 2024
@Alexey-T
Copy link
Owner

Alexey-T commented Sep 20, 2024

Why the memory grows so much - because Undo-list design is not compact. for typing 1 char with 18k carets - undo-list contains 18k items and each item contains 18k*4 integers (and other infos). what will help here is redesign of Undo-list internal format. maybe I will look at it later, not sure.

Current workaround which I suggest: smaller value of "undo_max_carets". eg 1000.

EDIT
I will decrease default of "undo_max_carets" for the next version.

@njwgh
Copy link
Author

njwgh commented Sep 20, 2024

Thanks!. I confirm that with undo_max_carets = 1000, then I can do the edits and they are quite quick.
can you explain how undo_max_carets value works. I assumed that if number of carets was > undo_max_carets then it wouldn't save any undo information, but that is obviously not how it is working.

@Alexey-T
Copy link
Owner

Maybe you tested it wrong? As I know that option must work like you guessed... So with 18k carets, option value 16k must also make it fast.

@Alexey-T
Copy link
Owner

(Marked as 'enhancement' because there is no bug but I see the room for improvement of too big memory usage)

@njwgh
Copy link
Author

njwgh commented Sep 21, 2024

Maybe you tested it wrong? As I know that option must work like you guessed... So with 18k carets, option value 16k must also make it fast.

I think you're right. I checked again and 10000 for max_undo_carets works with my file. Not sure what happened the first time

@Alexey-T Alexey-T changed the title out of memory errror, large number of carets inserting text out of memory error, when typing a char with 18k carets (almost the limit of "undo_max_carets") Sep 21, 2024
@Alexey-T Alexey-T changed the title out of memory error, when typing a char with 18k carets (almost the limit of "undo_max_carets") out of memory error, when typing a char with 18k carets (almost the limit of "undo_max_carets": 20000) Oct 15, 2024
@Alexey-T
Copy link
Owner

Alexey-T commented Oct 27, 2024

proper fix will be:

  • don't write CaretsArray to UndoItem for multi-carets editing, except for the last affected caret. ie, we have 100 carets, and do 'arrow right' command typing a char. we must not write CaretsArray for first 99 UndoItems, only write CaretsArray for the last UndoItem. typing action is performed as grouped, so 'middle' caret info is not needed anyway
  • when doing Undo for UndoItem, see if it has empty CaretsArray, and if so, don't move / delete carets at all

this will give O(caret_count) mem usage for Undo. current usage: O(caret_count^2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants