-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
NFC: Cache plugin name not full path, saves some RAM #3737
Conversation
Trimming the suffix does not save you any memory (as the allocation is not getting shrunk), so is there a point in doing so and then re-concatenating it? |
Yes. Because the path with suffix is being saved in the cache. It's concatenating again when loading from file, but if it wasn't removed it would be kept around even in the cache. get_plugin() will construct the path that get_next_plugin() had trimmed, but load_cache() is calling get_next_plugin() in a loop and saving into cache with the resulting name from get_next_plugin(). So instead of full path with parent directories and name suffix, it only keeps in cache the name, which is the only varying value between the plugin paths. |
It doesn't really save memory during the loop that's true, but it's preventing redundant data from being kept in the cache |
Sure, but if you are not saving any memory by trimming the suffix, then you are only wasting cycles to reconstruct it and not gaining anything in return. Unless I am missing something. |
It is saving memory. Sure you can debate if it's better to save ram or a few clock cycles, but there is definitely a ram save here. Look at line 184/191, instead of the full path, it's saving just the name into the cache array. The purpose of cache is knowing which plugins contain which type of functionality, so when going to parse a nfc tag / saved file, it doesn't need to load every single plugin, but only relevant ones. As it stands currently, the cache array contains paths. Cache array before:
This is redundant data, instead the can just save the names. Cache array with this PR:
|
You're looking only at get_next_plugin() and get_plugin(), where one trims the path and the other reconstructs it. This is not the memory save itself, this is what enables the memory save, because load_cache() is then saving the trimmed name that get_next_plugin() made into the cache, and so it saves less data, only relevant one. |
OK, I see it more clearly now - |
@gornekich can you take a look? |
Hi @Willy-JL , thanks for PR! |
that looks perfect, thank you! |
Co-authored-by: gornekich <gornekich@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
What's new
Verification
Checklist (For Reviewer)