haydenull / logseq-plugin-git

A git plugin for logseq
MIT License
115 stars 24 forks source link

Interface Slowdowns on MacOS #6

Open zpeters opened 2 years ago

zpeters commented 2 years ago

I started experiencing "slowdowns" in logseq that i couldn't explain. As i was filing a bug with their main github repo, i think i narrowed down the issue to this plugin. Below is my experience and how i reproduce the issue on my system. This is the same on an x86 or m1 mac. I have not tested this on Windows yet.

What happened?

After logseq has been open for a few minutes (to avoid any "startup" issues) it will randomly "slow down". Sometimes there is lag in navigating between pages, but this is most apparent when just typing. There will be a delay of several seconds between typing a letter and it appearing

Reproduce the bug

  1. open logseq version 0.7.1 on MacOS (all plugins disabled except logseq-plugin-git)
  2. wait a few seconds for the initial "surge" of cpu use on start up
  3. Go to "todays" journal, click on it so its the only thing being edited
  4. edit a new line/block
  5. type multiple words. notice that the first word is at a normal speed, subsequent words are delayed
  6. notice that cpu usage of Logseq spikes up to 99 %
  7. notice that clicking on the "three dots" menu is delayed
  8. go into plugins and disable git plugin
  9. notice that there are no more delays
  10. go into plugins and re-enable git plugin
  11. notice there are no delays until next restart of the app

I have development experience, but have not worked on a logseq plugin yet. Im happy to provide more testing and potentially a PR if i can get some guidance on getting started to with plugin development

Thanks for the great plugin! Im very motivated to help get this fixed because it is a very important part of my workflow.

zpeters commented 2 years ago

I am not too fluent with javascript, but after digging around i found the root of the issue. I dont understand why, but im narrowing it down.

In the following code in main.tsx is what appears to cause the delays. In my thought process there is something in checkStatus that is blocking when it should by async?

logseq.DB.onChanged(async () => {
      setTimeout(() => {
        checkStatus()
      }, 1000)
    })
dgraziotin commented 2 years ago

I can confirm this issue. A single keystroke will cause the following entries in the console

3index.8e262b56.js:87 Checking status...
index.8e262b56.js:80 [faiz:] === git status {stdout: ' M journals/2022_06_06.md\n M logseq/pages-metadata…n action research.edn"\n?? journals/2022_06_07.md\n', stderr: '', exitCode: 0}
index.8e262b56.js:87 Need save {stdout: ' M journals/2022_06_06.md\n M logseq/pages-metadata…n action research.edn"\n?? journals/2022_06_07.md\n', stderr: '', exitCode: 0}
index.8e262b56.js:80 [faiz:] === git status {stdout: ' M journals/2022_06_06.md\n M logseq/pages-metadata…n action research.edn"\n?? journals/2022_06_07.md\n', stderr: '', exitCode: 0}
index.8e262b56.js:87 Need save {stdout: ' M journals/2022_06_06.md\n M logseq/pages-metadata…n action research.edn"\n?? journals/2022_06_07.md\n', stderr: '', exitCode: 0}
index.8e262b56.js:80 [faiz:] === git status {stdout: ' M journals/2022_06_06.md\n M logseq/pages-metadata…n action research.edn"\n?? journals/2022_06_07.md\n', stderr: '', exitCode: 0}
index.8e262b56.js:87 Need save {stdout: ' M journals/2022_06_06.md\n M logseq/pages-metadata…n action research.edn"\n?? journals/2022_06_07.md\n', stderr: '', exitCode: 0}

The 3index line means that the entry is repeated 3 times.

As with @zpeters, I am not familiar with logseq plugin system, but it looks like logseq.DB.onChanged gets triggered at each keystroke. Calling checkStatus every single time might be the culprit.

Happy to test fixes. Your plugin is a fundamental part of my workflow.

bdillahu commented 2 years ago

Not sure about reason, but can confirm performance was unacceptable (on Mac) with plugin enabled. Happy to test if needed.

haydenull commented 2 years ago

Version 1.2.0 added the checkWhenDBChanged option to manually disable listening to logseq.DB.onChanged.

In addition, I have submitted the issue to logseq.

You can test whether the problem is resolved.

zpeters commented 2 years ago

Thank you @haydenull !

dgraziotin commented 2 years ago

Thanks, @haydenull, for the quick fix! Hopefully they fix it upstream as well.