Fix: RAM Usage Larger Than It Should Be #1310
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to #1268
An issue was reported where the Linter would cause Obsidian to freeze on a large file. I thought it would be like the others where it froze because the Linter was long running. And while that is partially the cause, I encountered an issue where Obsidian would crash on me due to high RAM usage (an OOM error). After debugging the process and trying to figure out what was going on, I was able to determine that using
substringon a string was creating a pointer to it. So I was accidentally keeping around many references to the original copy of the string I was then updating in the ignore types logic. This meant that since the file in question was about .9MB, I was getting this file's size roughly duplicated for each value replaced. In the file, it was more than 300 times. To fix this, it is best to first get all of the substrings and then update the string. This way we only keep one extra instance of the text present. This drastically reduced the RAM usage.I also added some logic to limit the amount of characters from a file that can be logged to also help keep RAM usage low.
Changes Made: