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

High CPU Usage and unrecognized characters in .js file #315

Open
JasonL708 opened this issue Apr 22, 2023 · 2 comments
Open

High CPU Usage and unrecognized characters in .js file #315

JasonL708 opened this issue Apr 22, 2023 · 2 comments

Comments

@JasonL708
Copy link

Whenever I enable the plugin, the CPU usage of Obsidian will start to increase and stay elelvated, and the Obsidian app simply because too slow to use. Once I disable the plugin then everthing normalized.

Then I went to the plugin folder and tried to open the .js file to see if I can make sense of the problem. But then I saw these unrecognized wierd stuff (see the screenshot blow)... Not sure what is happening here but it's an absolute pity for me not being able to use the plugin. Could you please help? Thank you!
Screenshot 2023-04-22 112205

@Violin9906
Copy link

I have the same issue on Windows version v1.3.5. It seems that this issue was introduced in 0.2.7, so I downgraded it to 0.2.6 and it works fine.

@matthewturk
Copy link
Contributor

I was able to verify that on my machine, a Performance profile showed a very large amount of CPU usage from the annotator plugin when it was enabled and Obsidian was idle. When I disabled it, the CPU usage was much lower and flat.

Looking at what @Violin9906 suggested, I tested out disabling the styleObserver:

app.plugins.getPlugin("obsidian-annotator").styleObserver.unwatch()

When I turned it off, the results were as though it was not enabled -- mostly idle. Turning it back on:

app.plugins.getPlugin("obsidian-annotator").styleObserver.watch()

had the CPU usage go way up again. The pattern looked something like this:

image

In the code, it looks like regardless of what styleObserver.interval is set to, it calls it with a value of 250, and inside that it does what could be a reasonably expensive set of calculations. For instance, I'm currently using the ITS-Theme and that can include a bunch of embedded base64 representations of fonts and icons. I think this means that every 250ms, annotator is concatenating all the CSS then doing a string comparison on the two packed strings.

At present, I also noticed that my listeners array is empty. So even if the CSS does change, I won't have anything notified of the change.

Would you be open to a pull request that utilized styleObserver.interval instead of the value 250? Or, alternately, an option that allows disabling this entirely? (That might result in some weird visual effects, right?) Or, perhaps best, what if the interval was set and the anonymous function returned early if this.listeners.length === 0?

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