Open wadbr opened 3 years ago
I came here for the exact same reason. This issue is causing up to 10% CPU usage constantly. Not Obsidian causing this much usage but my syncing tool. It took me a couple of days to figure out what is causing this and deactivating this plugin finally solved my issue.
So there is something going wrong there.
And after taking a quick glance at the source I think I found one issue that could cause this. But I didn't test it yet:
this.registerInterval(window.setInterval(() => { this.updateDate(); this.saveSettings(); }, 1000));
I'm not that familiar with JS/TS and Obisdian plugin programming. But this seems to me like you are setting an interval to 1000ms and it is updating the date and saving the settings every 1000ms? Why would you want to do that?
It would be more reasonable to save the settings only if something actually changed. And update the date at startup and every hour after that.
did this get fixed?
This is not yet fixed. I came here for the same reason. It's driving Obsidian sync crazy and making network traffic on my work machine very wonky. It's only a small amount of data, but, it seems like it'd be much better to allow this to be configurable or to have a setting of some sort. I love the idea of this plugin and seeing my word count, but, have currently disabled it due to this.
A few things that can probably be done:
This is because the plugin is writing to its data.json
file every second, regardless of if there's new data. We could store the word count from before the most recent check in memory and use it to avoid updating the file for this cycle.
this.settings.dayCounts[this.today] !== this.previousWordCount
There's currently this bit o' logic:
this.debouncedUpdate = debounce((contents: string, filepath: string) => {
this.updateWordCount(contents, filepath);
}, 400, false);
Haven't looked entirely into how debouncedUpdate
behaves but it seems like every 400ms after a file update, we take all contents of the file, count the number of words, then update the word counts. I imagine we could change that false
to true
and it would change to only running this code after there hasn't been any typing for 400ms.
Potential downside: if you're a fast typer, you won't see your word count update on the status bar until you pause for less than half a second. That's still a really fast update, but not the almost real-time speed we have now.
Upsides: While I doubt this would be a concern for most text files, we are currently running a bunch of regex for practically every keystroke. This would defer getting the word count of the file until the user has a brief pause. We can then also get rid of the interval, and only update our data.json
when the user pauses rather than doing a check every second.
Any thoughts?
@AndrewNatoli given the data that I see in data.json for this plugin, it seems like storing the changeset in memory until buffer close, obsidian close, etc. would be a good idea. Can render from memory and/or reading from the file for all readouts and this should be manageable for even large obsidian vaults. I believe this would drastically lower the number of updates to the file alone as there'd be no reason to write or update the file unless an editor window changed. This would also reduce the likelihood of a collision when running this on multiple computers with obsidian sync enabled.
Debounced update also seems like a good idea, and honestly, if that one works as you'd expect having a configurable number so you can set the speed you'd like it to update at would be useful. One person may enjoy seeing the number fly up as they type words, while another might want it to really only update if they've paused for 10-15 seconds.
I've been brainstorming for other solutions as well. I had minor hope I could just exclude this plugin's folder from sync, but, unfortunately the exclude functionality doesn't seem to be able to 'see' the .obsidian folder even if entered manually.
It would be nice if someone who knows what they are doing update this plugin, fixing this.
As the title says, pretty simple to explain really :D
Why is this an unwanted behavior?
Maybe stopping the updates when obsidian is minimized is better behavior since i dont know if there's any use of the plugin if you aren't using the app directly.