Cache the DetectableDB scan results#123
Conversation
|
Seems like it works with some slight reduction in cpu and memory usage as well. I will update after trying in combination with #92 but it seems good so far. |
|
It appears in combo with 92 the cpu and memory usage goes up but not by much. I do see the memory usage going up at a very slow rate consistently while idling and slightly faster while multiple different processes are running. I have direct contact with chlorobyte if anyone asks how I managed to test the combined pr. |
CanadaHonk
left a comment
There was a problem hiding this comment.
Wow this is great, thank you! Small request: could you just store detected in the cache instead of { detected }?
This prevents a hypothetical case of rotating lots of processes to bloat the RAM usage
|
Sure, that makes sense. Also implemented some sort of garbage collection to resolve @Dekomoro's concern, in a normal use case you basically never hit this (or maybe you do like once an hour of runtime or something) |
|
When evaluating this change, I was really blown away by the performance improvements. Using the logging in Additionally, running clinic.js BeforeAfterLooking forward to seeing this merged, amazing work. |
|
|
||
|
|
||
| const timestamps = {}, names = {}, pids = {}; | ||
| const timestamps = {}, names = {}, pids = {}, cache = {}; |
There was a problem hiding this comment.
I know most of these already existed before this PR, but using plain objects for this is bad. When you have frequent writes / deletes, Maps perform way better, both in terms of speed and memory usage. Changing all of these to Maps might also make it perform better


Inspired by a performance problem rightfully pointed out in PR #92, I set out to greatly optimize the process scan:
mainmain, simply no GC spikes happened hereThe change works on my end, but is also provably correct (assuming
DetectableDBdoes not change) because:DetectableDB's contents,args, andtoComparetoCompareis derived fromsplitPathsplitPathis derived frompathNotes:
await Native.getProcesses();. Improve linux game detection #92 does add functionality to this call but the performance difference is negligible (16.3ms -> 18.3ms, possibly within margin of error)DetectableDB.Open questions:
DetectableDBentries being detected with one process is intentional, but I cache an array of all detected entries to keep this behavior