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

Plugin keeps rewriting and recreating data.json every couple of seconds even when obsidian is minimized and not in use #6

Open
wadbr opened this issue Apr 21, 2021 · 7 comments

Comments

@wadbr
Copy link

wadbr commented Apr 21, 2021

As the title says, pretty simple to explain really :D

Why is this an unwanted behavior?
- constant cpu and disk usage (my vault is in a secondary disk, it cant hibernate while not in use if a file keeps being written)
- sync app constantly working since the folder changes

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.

@brightknight2
Copy link

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.

@brightknight2
Copy link

brightknight2 commented Nov 10, 2021

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.

@ADB991
Copy link

ADB991 commented Apr 22, 2022

did this get fixed?

@powder
Copy link

powder commented May 4, 2022

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.

@AndrewNatoli
Copy link

A few things that can probably be done:

1. Addressing the sync issues

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

2. Debouncing updates rather than using an interval

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?

@powder
Copy link

powder commented May 4, 2022

@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.

@Drakemoor
Copy link

It would be nice if someone who knows what they are doing update this plugin, fixing this.

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

6 participants