cwtools / cwtools-vscode

A VS Code extension providing language server support for paradox script files using cwtools
Other
88 stars 12 forks source link

Reducing RAM usage #91

Open PerplexedPeach opened 1 year ago

PerplexedPeach commented 1 year ago

This extension is taking up around 4-5GB of RAM, making it hard to use together with the game open. I suspect it's because my workspace has too many CK3 projects in it, but I'm not sure if this contributes to it. Does having more CK3 files in a workspace (without opening) them increase RAM usage? My workspace includes:

Another possible culprit is that many of my event files are autogenerated via a python script, so I have like 20k line files that should be excluded from processing. Is there a way to mark files or directories as excluded from indexing?

tboby commented 1 year ago

Does having more CK3 files in a workspace (without opening) them increase RAM usage?

Yes: cwtools keeps a processed form of every script and localisation file in it's scope in memory.

It's basically unavoidable if you want to have anything responsive, and all programming languages have high memory usage if you want to open several projects at once sadly!

At a minimum this would be the "vanilla cache" which contains all the vanilla files, plus your mod. If you're including the base game in your workspace you might be causing it to load all of vanilla again. If your mod is a total conversion, you'd then effectively be keeping three copies of vanilla around :)

One recommendation I have would be to create multiple workspaces, where some contain only your core mods + dependencies. This is the approach taken in other languages when solutions get too large.

The huge files will cause some problems, although if they're over 2MB they're probably already being ignored by the default max file size setting cwtools.maxFileSize. There's also cwtools.ignore_patterns which you could use to ignore whole filepaths, which you should be able to use to ignore your reference inclusion of vanilla.

PerplexedPeach commented 1 year ago

I see, thanks! Those are all actionable and I'll get back to you with how well some of them work.

PerplexedPeach commented 1 year ago

Removing the base game and some other mods from the workspace reduced it down to around 3.5GB of RAM, so that worked as intended. The cwtools.ignore_patterns doesn't seem to be working. When I put a single string there (not even utilizing any glob patterns; it's just the path relative to the workspace of one of my event files), the extension just stops working - the cwtools loaded files tile in the bottom left is completely empty and it makes no attempt to load anything. Is there a way to debug the extension settings?

EDIT: disabled then re-enabled the extension and reopened vscode 3 times to get it to populate the loaded files tile again, but the specified path wasn't ignored. Are the filepaths not relative to workspace (are they absolute)?

EDIT: is there a way to ignore all rules / stop linting? That should probably reduce the RAM usage significantly. I know I can manually specify individual rules to ignore via cwtools.errors.ignore, but that's not ideal. Could I set rules_version to manual then specify a non-existent or empty path in rules_folder? The rules are almost entirely noise since 99% of it is false positives even on rules_version: latest. Maybe this is a separate issue, but I get errors for statements that work like:

chance_to_happen is unexpected in random_eventsCW262
triggered_outfit is unexpected in left_portraitCW263(CW263)
Missing event_background, expecting at least 1CW242(CW242)
reference is unexpected in override_backgroundCW262(CW262)
has_trait_xp is unexpected in limitCW263(CW263)
multiply is unexpected in valueCW262(CW262)
any_normal_councillor is unexpected in ORCW263(CW263)

EDIT: I would like being able to search in the vanilla files within the workspace. I think the best way to accomplish this is to add the vanilla folder to the workspace but ignore it using cwtools.ignore_patterns once I figure out how to use that.