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

macro issue causing heavy system load #145

Closed
marilmanen opened this issue Dec 30, 2019 · 5 comments
Closed

macro issue causing heavy system load #145

marilmanen opened this issue Dec 30, 2019 · 5 comments

Comments

@marilmanen
Copy link
Contributor

marilmanen commented Dec 30, 2019

I use a macro for searching text from my files and sometimes it causes heavy system load (can be seen as very fast cursor blinking rate). Issue seems to be related cursor focus with detached tabs and it looks like it requires a random amount of macro iterations or at least I have not found a simple way to reproduce the issue. Consecutive selections with focus changing between files in different tabs and at some point the cursor starts behaving badly and system load of the nedit-ng process goes to 100%.

strace command for the nedit-ng process shows an infinite itaration of

poll([{fd=3, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=3, revents=POLLOUT}])
writev(3, [{">\0\7\0\301\24\300\5\5\0\300\5\302\24\300\0052\0\24\0012\0\24\1'\4$\0008\0\4\0"..., 44}], 1) = 44
recvmsg(8, 0x7ffceb60edb0, 0)           = -1 EAGAIN (Resource temporarily unavailable)
recvmsg(8, 0x7ffceb60edd0, 0)           = -1 EAGAIN (Resource temporarily unavailable)

Here is the macro code

if ($selection_start > -1) {
  string = get_selection()
} else {
  string = string_dialog("Give string to grep")
}
matches = shell_command("grep -ni '" string "' * | grep -v ^grep:", "")
if ( matches != "" ) {
  selection = 1
  while ( selection != "" ) {
    selection = list_dialog( "Select a line to go", matches )
    if ( selection != "" ) {
      file = selection
      file = replace_in_string(file, ":.*", "", "regex")
      line = selection
      line = replace_in_string(line, ":(\\d+).*", ":\\1", "regex")
      line = replace_in_string(line, ".*:", "", "regex")
      open($file_path file)
      focus_window($file_path file)
      goto_line_number(line)
    }
  }
}
@eteran
Copy link
Owner

eteran commented Dec 31, 2019

Interesting, I'll look into it

@eteran
Copy link
Owner

eteran commented Dec 16, 2020

@marilmanen I have found a good way to reproduce this bug locally, and it does seem to be having to do with things that change the focus document.

I was even able to replicate with ctag operations (not macros).

I think I know WHAT is happening, just not WHY it is happening. Basically, under some very specific circumstances, the timer object I use to redraw the cursor acts like it has a timeout of 0 instead of like 500 milliseconds, thus repainting constantly and burning CPU.

@anjohnson
Copy link
Contributor

I see the flickering cursor occasionally too. One way I can trigger it (on Mac) is in the Open File dialog start typing a filename, use cursor-down to select a file from the list of matching names that pops up, then press return to open it. That tab seems to always have a flickering cursor, but the other tabs aren't affected.

@eteran
Copy link
Owner

eteran commented Dec 16, 2020

Yup, I have a fix incoming!

eteran added a commit that referenced this issue Dec 16, 2020
eteran added a commit that referenced this issue Dec 16, 2020
@eteran
Copy link
Owner

eteran commented Dec 16, 2020

OK, should be fixed in master!

Basically, the issue was that QTimer::start will use the previously set interval if none is specified. That works great, but apparently, the change focus event if switching to a window you haven't set the focus on before will call start() before any previous focus events set the interval, making it use the default interval of 0.

Fixed by explicitly setting the interval when the timer is created, so it will always be correct.

@eteran eteran closed this as completed Dec 16, 2020
1div0 pushed a commit to 1div0/nedit-ng that referenced this issue Dec 29, 2020
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

3 participants