The following function creates an Audio Analysis Object, which itself has a
size of 64 bytes (as per sys.getsizeof), but the function itself is
using over 100MB
of memory for a 6MB
mp3 file.
def main(input_filename):
audiofile = audio.LocalAudioFile(input_filename)
I've profiled using memory_profiler (thanks to Huy Nguen) and also used Pympler
(from SO answer) to explore the sizes, number and types of objects (results of which are shared below. Even confirmed the size of the inputfile itself from within Python using os.stat(input_filename)
with statinfo2.st_size
. The total size of the file and object combined appears to be 11MiB
(basically MB).
Does this mean I have to dig deeper into the calls made by the LocalAudioFile
class which creates the object? And if so, does that need to be done within the code of the external module itself, or perhaps by experimenting with a duplicate of it's code?
types | # objects | total size
============================ | =========== | ============
dict | 2564 | 3.42 MB
str | 14790 | 2.43 MB
float | 35420 | 830.16 KB
unicode | 9552 | 792.63 KB
code | 5670 | 708.75 KB
list | 3160 | 606.56 KB
type | 484 | 427.28 KB
wrapper_descriptor | 1658 | 129.53 KB
tuple | 1227 | 91.00 KB
builtin_function_or_method | 1094 | 76.92 KB
weakref | 894 | 76.83 KB
method_descriptor | 899 | 63.21 KB
set | 151 | 53.21 KB
getset_descriptor | 645 | 45.35 KB
int | 1657 | 38.84 KB
Memory profiling results:
Line # Mem usage Increment Line Contents
================================================
30 20.395 MiB 0.000 MiB @profile
31 def main(input_filename, input_filename2):
32 24.250 MiB 3.855 MiB audiofile = audio.LocalAudioFile(input_filename) #250kb audio file
33 139.988 MiB 115.738 MiB audiofile2 = audio.LocalAudioFile(input_filename2) # 6MB audio file
#irrelevant profiling code removed
47 146.531 MiB 0.477 MiB summary.print_(sum1)