Improved performance of call_and_shelve#757
Conversation
Codecov Report
@@ Coverage Diff @@
## master #757 +/- ##
==========================================
- Coverage 95.42% 94.62% -0.81%
==========================================
Files 43 43
Lines 6208 6210 +2
==========================================
- Hits 5924 5876 -48
- Misses 284 334 +50
Continue to review full report at Codecov.
|
|
Nice one! It would be great to also add a test. |
|
Sure I could write one. I have been thinking about what should be tested, but did not find any good idea. Indeed, this PR does not change, add, nor removes any functionality. Just a tiny bit of the implementation of the current functionalities. I could test that the performance remains below a given threshold, but I'm not so sure it is a good idea (mainly because it depends on the worker of the test). I could also mock the store_backend and assert that it has not been called, but : it depends on the implementation, and I have not been able to find any use of mocking in the entire repository. It is the best idea I was able to come up with nonetheless. What do you think about it ? |
I had the same idea and that's what I would also do. But maybe other maintainers have better ideas. @lesteve @ogrisel @tomMoral, what do you think ? |
|
I think it's fine not to add any new test in this case. We could have an automated benchmark suite for performance test (for instance using airspeed velocity) but this would require some significant infrastructure investment. |
|
LGTM, merging. Thank you very much for this contribution @MaximeWeyl ! |
|
You're welcome ! |
* tag '0.12.3': (23 commits) Release 0.12.3 Loky 2.2.1 (joblib#760) FIX: FileSystemStoreBackend string representation only returning location (path) (joblib#765) Add optional dependency on psutil MAINT remove brittle time based assertion in test (joblib#761) Fix a bug in nesting level computation with FallbackToBackend(SequentialBackend()) (joblib#759) Make docstring more consistent with project style Improved performance of call_and_shelve (joblib#757) Better test name Fix default context handling (joblib#754) cloudpickle 0.5.5 (joblib#756) Fixed error where filter args was consuming kwargs (joblib#750) FIX pickle roundtrip for Memory and related classes. (joblib#746) test that passes but timeout appveyor because of unclosed semaphore tracker (joblib#676) DOC: fine tune compressor example dataset size for ReadTheDocs (joblib#753) FIX: MemorizedResult not picklable (joblib#752) [MRG] Better message with py27 when lz4 is not installed (joblib#740) MNT remove mutable default value for backend_options parameter (joblib#748) MNT create test file for _store_backends module (joblib#749) DOC consistently use memory rather than mem in memory.rst (joblib#744) ...
* releases: (23 commits) Release 0.12.3 Loky 2.2.1 (joblib#760) FIX: FileSystemStoreBackend string representation only returning location (path) (joblib#765) Add optional dependency on psutil MAINT remove brittle time based assertion in test (joblib#761) Fix a bug in nesting level computation with FallbackToBackend(SequentialBackend()) (joblib#759) Make docstring more consistent with project style Improved performance of call_and_shelve (joblib#757) Better test name Fix default context handling (joblib#754) cloudpickle 0.5.5 (joblib#756) Fixed error where filter args was consuming kwargs (joblib#750) FIX pickle roundtrip for Memory and related classes. (joblib#746) test that passes but timeout appveyor because of unclosed semaphore tracker (joblib#676) DOC: fine tune compressor example dataset size for ReadTheDocs (joblib#753) FIX: MemorizedResult not picklable (joblib#752) [MRG] Better message with py27 when lz4 is not installed (joblib#740) MNT remove mutable default value for backend_options parameter (joblib#748) MNT create test file for _store_backends module (joblib#749) DOC consistently use memory rather than mem in memory.rst (joblib#744) ...
Here is a pull request that improves the performance of MemorizedFunc.call_and_shelve when a result has already been cached.
Basically, before the code request, joblib loads the entire cached file into memory, returns a reference to the file and forgets about what is in memory.
With this pull request, joblib creates the reference without loading the file into memory.
This PR passed the Travis tests on my fork.
Simple Benchmark
Definitions
Before the pull request
First call (no cache exists)
It takes 1m34s to create and return the cached array.
Second call (array is already cached)
It takes 19.7s to get a reference on the array.
Loading into memory
Then it takes 11.9 seconds to load the reference into memory.
After the pull request
First call (no cache exists)
It still takes time to create the cached object.
Second call (array is already cached)
It takes 120ms to get a reference on the array.
It took near 20s before.
Loading into memory
Then it takes 21.3 seconds to load the reference into memory.