psethwick / plover_console_ui

Text User Interface plugin for Plover
GNU General Public License v3.0
20 stars 2 forks source link

High CPU usage, occasional hang #8

Closed user202729 closed 3 years ago

user202729 commented 3 years ago

It isn't really clear what's going on with the hang.

Since I'm using other plugins too (my web socket server that allows controlling Plover from other program, the pull request to delay output characters), the bug could be in these too, or only become apparent when combined with this plugin.

But the CPU consumption (while something is stroked) appears to be higher than that of the qt GUI plugin.

More details later.

...

I observe that the paper tape and the suggestions calculation always run even if the windows are not opened. I guess that's the cause. (and it's definitely a waste of CPU, since most users wouldn't want to see it)

Is it acceptable to have no suggestion unless the window is opened? (I think it's done like this in the qt gui version?)

user202729 commented 3 years ago

It has high memory usage too. 1.6GB? Seriously?

psethwick commented 3 years ago

That's a lot! I will investigate. Totally possible to only have suggestions/tape running with them open, this was just what I chose for quick dev. (Hopefully that's where the CPU/memory is going)

Really appreciating the testing/issues, btw!

user202729 commented 3 years ago

Decide to tracemalloc it a little.

Total allocated size: 7603.5 KiB
Top 3 lines
#1: plover/steno_dictionary.py:160: 17163.3 KiB
    return set(self.reverse[value])
#2: plover/steno_dictionary.py:163: 1275.2 KiB
    return set(self.casereverse[value])
#3: layout/mouse_handlers.py:40: 646.4 KiB
    self.mouse_handlers[x, y] = handler
410 other: 1586.6 KiB
Total allocated size: 20671.6 KiB

Another snapshot:

[... same as above]
#3: plover/suggestions.py:44: 622.7 KiB
    for modded_translation in [mod % t for mod in mods]:
424 other: 973.7 KiB
Total allocated size: 23366.8 KiB

Looks like it's indeed the suggestion thing.

... wait, it's definitely a memory leak in Plover. That code doesn't make sense.

I opened a PR on the Plover repository. Will need to use it for a while to ensure that there isn't any other issues.

If there's nothing noticeable, this issue can be closed after a while.

Perhaps the hang is caused by dict reallocation or something.

psethwick commented 3 years ago

Huh, I didn't manage to reproduce anything like that.

#3: layout/mouse_handlers.py:40: 646.4 KiB self.mouse_handlers[x, y] = handler`

^^ this is weird, that's prompt_toolkit.layout not my .layout. I didn't expect mouse_handlers to run with mouse support off

psethwick commented 3 years ago

I've pushed a change to main so that suggestions/tape hooks are off unless the windows are open, that ought to help

Does seem like it must be a plover bug, though

user202729 commented 3 years ago

That one doesn't appear to increase over time, so it's not a problem.

Yes, I said it is (older post edited)

user202729 commented 3 years ago

Now the tape is broken. Surely automated testing is important. (perhaps this can be fixed quickly)

(not that I know how to use/set up one anyway)

│ERROR: hook 'stroked' callback <bound method Tape.on_││                                                        │
│stroked of <plover_console_ui.tape.Tape object at 0x7││                                                        │
│fcf3ab5e250>> failed                                 ││                                                        │
│TypeError: unsupported operand type(s) for *: 'NoneTy││                                                        │
│pe' and 'int'                                        ││                                                        |

Could be something with my Plover version too. But it used to work.

psethwick commented 3 years ago

I do plan to have a test suite! Mocking the plover stuff is tricky, though I think (python is a relatively new language for me).

Found the bug, it only occurs when tape is off on start up and turned on after :( (I had it configured on when testing it)

Will push a fix shortly

psethwick commented 3 years ago

I think this as resolved as it can be (in this plugin I mean), would you agree?

user202729 commented 3 years ago

I think so. Haven't experienced any hang since I fixed that Plover memory leak.