-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add a cache for samples #7497
base: master
Are you sure you want to change the base?
Add a cache for samples #7497
Conversation
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 markednoexcept
Sample::s_interpolationMargins
should be renamed toSample::InterpolationMargins
since it is publicsample_rate_t
could be used instead ofint
for 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 |
Adds an in-memory cache for samples. Callers can fetch data from the cache using two overloads: one for audio files, and another for Base64 strings. The cache stores weak pointers to the samples and returns shared pointers to the callers. However, the cache in the future will probably need to store the weak pointers along with sample thumbnails and possibly other kinds of metadata for each sample, which should be fairly easy to do as all that needs to be done is to store a collection of the data we need in a
struct
/class
instead of just the weak pointer to the buffer.For audio files, we check the last write time for the file to see if it needs updating each time it is fetched, and update it if necessary. For Base64 strings, we just compare the contents.
SampleLoader
loads audio data by querying the cache for it, rather than creating them manually. As such, theSampleLoader::create*
functions where renamed toSampleLoader::load*
.The memory usage has dropped significantly when using duplicate samples (
htop
readings went from 28.5% to 3.6% for me with a project that had a number of sample clips, each ~3 minutes long), and projects load faster (There is still some delay because of the waveform drawing, but this should be addressed soon. The speedup is more noticeable when you zoom all the way out before loading a project as a result).Should supersede #7058 I believe.