helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
34.03k stars 2.52k forks source link

Macros freeze the editor. #4428

Open kwinso opened 2 years ago

kwinso commented 2 years ago

Summary

I'm using helix v22.08.1. When using relatively long macro with a lot of lines, execution of macros freezes the editor completely. Only killing the process helps. Even 20 repetitions freeze editor for like 2 seconds.

Reproduction Steps

The macro:

# from this, but like 200 lines
'name'
# to this
INSERT INTO table(name) values('name') ON conflict(name) do nothing;

Helix log

No response

Platform

Linux

Terminal Emulator

Alacritty, latest release

Helix Version

helix 22.08.1

the-mikedavis commented 2 years ago

What was the macro?

kwinso commented 2 years ago

What was the macro?

Is there a way to copy macro's key sequence? (I recorded it into separate register)

the-mikedavis commented 2 years ago

You can paste out the contents of a register by pressing " then the key for the register (kbd>@</kbd by default for macros) and then p then copy that to the clipboard

kwinso commented 2 years ago

This is my macro (I commands separated with newlines so it's more clear what's going on):

i
# type: INSERT INTO
<S-I><S-N><S-S><S-E><S-R><S-T><space><S-I><S-N><S-T><S-O>
# type 'table(uuid, name)" and then skip autoclosed bracket with "li"
<space>table(uuid,<space>name<esc>li
<space>values(gen_random_uuid(),
# Remove auto-closed bracket, go to the end of the line to remove trainling "," 
# because I operated with a list of single-qouted strings separated by ",\n"
<space><esc>d<S-A><backspace>)
<space>on<space>conflict<space>(name<esc>li<space>do<space>nothing;<esc>
# Go to begging of next line
jgh

Just tried it, 40 repetitions take around 3 seconds.

archseer commented 2 years ago

It takes a lot of time because a lot of keypresses are executed. I think we can improve the performance by not re-rendering after every command though: https://github.com/helix-editor/helix/blob/c4d7cde6c8d7f5ca3a9cabd50bdfbda9c3f7bb15/helix-term/src/commands.rs#L4964-L4966 ui::Editor should not re-render while macro_replaying