-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add a cache for samples #7497
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
base: master
Are you sure you want to change the base?
Add a cache for samples #7497
Conversation
messmerd
left a comment
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.
Gave it a quick look-over.
Also,
Sample's move constructor and move assignment operator should be markednoexceptSample::s_interpolationMarginsshould be renamed toSample::InterpolationMarginssince it is publicsample_rate_tcould be used instead ofintfor the sample rate (See this commit for what needed to be changed: 10162ec)
Thanks, I will make another PR to address these issues separately. However, about the |
|
Any updates @messmerd? |
|
This PR looks pretty good to me code-wise. I'll test it next. |
|
I'm testing, and I'm finding no issues or bugs so far on Windows 11. I had 20 samples and samples randomly throughout lmms and the memory and the storage seems fine and not affected. The CPU meter inside lmms is not going up by that much and not heavy on the cpu. |
|
@messmerd, I believe I understand the benefit of using UUIDs better now. If the file path changes, then we only would need to update the mapping from UUIDs to file paths at one place, while all the other clients don't have to worry about anything and can continue using the UUID, which hasn't changed. As of right now my PRs handles it using the "last modified time", which has two problems. One, this can create a lot of dead entries if they are not being actively "garbage collected". Two, since clients still store the file path, if it changes, they would have to still manage the sample by themselves, and that would have to be done possibly everywhere. This is a problem in #7366, where we have check if the It seems like the overall idea here is to map UUIDs to assets/resources, which can be a sample file, sample Bas64 string, project file, preset file, etc. Assets can then specify if they are loaded from disk, or something else like as a string in the case of Base64 samples. Each asset can be updated as necessary to when the asset manager/cache feels like it should (changes on file system or something else possibly). This will not only bolster the sample caching implementation since it truly centralizes everything, but will also help make forward strides in simplifying and improving asset management (which may be needed for features like showing a popup to the user to load missing assets when loading the project, among other things).
|
|
@sakertooth Yep, that's exactly it. This PR doesn't make any changes to the project file as far as I'm aware, so it won't introduce any backwards incompatible changes if we merge it now. And since this PR is very useful as is, I think we should merge it then explore the UUID / resource manager idea in a follow-up PR. |
|
I'll at least move to using |
|
I read up on the docs for
I was a bit scared off making the switch because of this and had to weigh the pros and cons, so I'll probably leave the timestamp checking to be safe as it works well enough. A counter argument to having dead paths in the caches is that its rare and have static duration, so it really not that big of a problem as I made it out to be. The main issue is exposing the file path information that has to be made in sync everywhere else in the codebase, but we will deal with this later as already discussed. One change I should make though is that instead of making completely new entries, update preexisting ones if they are fetched a second time and are still valid on the file system. This should keep the number of invalid entries in the cache down by a fair amount. |
83ee767 to
90c3916
Compare
std::filesystem::path
|
Hi @messmerd, I scrapped the PR again and implemented it similar to how I did it the first time but with a different approach: I made a new class ( Since I did not cache Base64, but it can be added if necessary. Reason being is that Base64 is the data itself (as you know) and isn't really a key in the cache like a file path is. Since there really isn't any good key for that kind of data (except hashing it, which can be slow) as of right now, I have ignored it. I don't plan on going against the grain from this point, apologies if there was confusion on my end about this. I suppose I made things more complicated than they had to be. This PR is basically done on my end. |
std::filesystem::path91aa0eb to
ef0b9de
Compare
Adds support for caching resources from files. Currently, we use the new file cache for
SampleBuffer's andSampleThumbnail's, but it can be extended to other resources in the future. Uses the LRU eviction policy.Should supersede #7058 I believe.