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

Ideas for improving performance during macro execution #179

Open
Subjective opened this issue Jul 26, 2023 · 2 comments
Open

Ideas for improving performance during macro execution #179

Subjective opened this issue Jul 26, 2023 · 2 comments

Comments

@Subjective
Copy link

I like how leap works consistently with macros, and imo this is a really big selling point over alternatives like flash, but it doesn't always perform the best compared to using native f/F (which is almost instantaneous), especially with custom hl groups and highlighting patterns (like for underlining urls on screen).

Screen Recording 2023-07-24 at 8 00 26 PM

Now this isn't specific to leap (sneak also suffers from poor performance during macro execution), but I do believe this can be improved. Just as a suggestion, I was thinking that during macro execution there is no need for leap to search for all occurences of a pattern on screen as the user has already determined the nth occurence to jump to during recording ahead of time. For instance, if the macro contains the search pattern is [s]exf or [s]ex{repeat key × 2}, leap should only find the 2nd occurence of ex, jump to it, and nothing more. Of course, this would be dependent on the safe labels the user has configured.

One caveat I can see right now is that currently leap doesn't not always immediately jump to the first occurence of a pattern if there are many matches (18 or more). I thought this had to do how I configured the options max_phase_one_targets and
max_highlighted_traversal_targets, but as far as I can tell, that doesn't seem to be the case. Right now I'm not really sure if this is a bug or not.

Potential Bug?

Screen Recording 2023-07-25 at 4 56 57 PM

As for highlighting, I believe that can be naively disabled during macro execution on the user's end with something like this:

vim.on_key(function(key)
  if key == "s" and vim.fn.mode=="n" and vim.fn.reg_executing() ~= "" then
    -- ensure hl groups/highlighting patterns are disabled
  end
end)

But I think it would be cool if this functionality was built in, or maybe a configurable option that takes a custom function to be called during macro execution.

All in all, I'm not entirely sure how feasible this is or how much effort it would take. I just thought I would put it out there for discussion. Thanks for your consideration!

@ggandor
Copy link
Owner

ggandor commented Jul 26, 2023

I like how leap works consistently with macros, and imo this is a really big selling point over alternatives like flash

Interesting, Flash doesn't?

especially with custom hl groups and highlighting patterns (like for underlining urls on screen)

Try setting lazyredraw, at least the flickering would stop, but performance-wise I don't think that redrawing is the main offender here.

One caveat I can see right now is that currently leap doesn't not always immediately jump to the first occurrence of a pattern if there are many matches (18 or more)

https://github.com/ggandor/leap.nvim#smart-autojump. You might want to set either safe_labels = {} or labels = {} on RecordingEnter (and restore on RecordingLeave), so that the recorded key sequence will correspond to the same action.

I was thinking that during macro execution there is no need for leap to search for all occurences of a pattern on screen as the user has already determined the nth occurence to jump to during recording ahead of time. For instance, if the macro contains the search pattern is [s]exf or [s]ex{repeat key × 2}, leap should only find the 2nd occurence of ex, jump to it, and nothing more.

Indeed, but for this we'd have to parse the content of a register being executed, which is a hackish thing in the first place, but on top of that, the sequence depends on the user's keymappings, so this is out of the question.

Edit: Or maybe we could save the target if reg_recording(), and skip all unnecessary stuff if reg_executing(), similar to a dot-repeat. Hmm.

@Subjective
Copy link
Author

Interesting, Flash doesn't?

Well it works, but the labels are just way to unpredictible because of the bidirectional search and also potentially change due to the variable search pattern, so I can't really see myself using it for macros.

Try setting lazyredraw, at least the flickering would stop, but performance-wise I don't think that redrawing is the main offender here.

Yeah you're right, after further investigation it doesn't seem like the highlighting causes too much of an issue - it's mostly just the regex pattern I'm using to highlight URLs that seems to be the source of the laggy leaping.

You might want to set either safe_labels = {} or labels = {} on RecordingEnter (and restore on RecordingLeave), so that the recorded key sequence will correspond to the same action.

Thanks, that's good to know!

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

No branches or pull requests

2 participants