You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TagLib::FileRef and MPEG::File very slow destructor #1010
I'm using taglib for a media player
Is very fast to get mp3 tags and embedded pixmaps, but destructor is very slow:
in Ryzen 3900X /linux:
parse time arround 1-25ms per mp3
destructor is arround 100ms !!!
----> parse interval 15 ms
----> parse interval 21 ms
----> parse interval 24 ms
----> parse interval 25 ms
----> parse interval 35 ms
----> parse interval 34 ms
----> parse interval 40 ms
----> destructor interval 105 ms
----> destructor interval 109 ms
----> destructor interval 106 ms
----> destructor interval 107 ms
----> destructor interval 102 ms
----> destructor interval 106 ms
The type of audio file could be relevant to answer this question, because the concrete destructor implementations differ. I would not expect that closing the files takes so long when you are only reading from them. Could you please profile the situation further, e.g. using Valgrind (menu Analyze/Valgrind Function Profiler in Qt Creator). You could also try KCachegrind. I can also recommend Gperftools.
It's worth noting that what you may be timing is not the destructor, but the debugging statement that's in the block; often printing is slow. Also, the timer is cumulative, so it's more like the time between the first and second print statements is 65-90 ms.
I had a look at this issue. When I open a file on my internal SSD, the time spent in the destructor is small. However, if I open a file on a USB stick, I can confirm that the time spent in the destructor is above 100ms. Tracking the calls down, it can be seen that most of the time is spent in fclose(). I can just instrument closeFile() in tfilestream.cpp to print the time in us (using #include <sys/time.h> on Linux):
If the file is opened in read-only mode, fclose() is fast. When editing tags, it is possible that it is not known in advance if a file has to be modified. So an idea for improvement could be to always open files in read-only mode (fopen() with mode rb) but store the information if a file is allowed to be written and then change the file mode to rb+ using freopen(0, "rb+", d->file) when allowed and necessary, i.e. before a call to the writeFile() function in tfilestream.cpp. However, I am not sure if this is a good idea, especially the sentence
It is implementation-defined which changes of mode are permitted
Activity
ufleisch commentedon May 8, 2021
The type of audio file could be relevant to answer this question, because the concrete destructor implementations differ. I would not expect that closing the files takes so long when you are only reading from them. Could you please profile the situation further, e.g. using Valgrind (menu Analyze/Valgrind Function Profiler in Qt Creator). You could also try KCachegrind. I can also recommend Gperftools.
scotchi commentedon May 8, 2021
It's worth noting that what you may be timing is not the destructor, but the debugging statement that's in the block; often printing is slow. Also, the timer is cumulative, so it's more like the time between the first and second print statements is 65-90 ms.
mapons commentedon May 10, 2021
Now I using readonly version, and is faster:
RO 1-15ms
RW 100 -125ms
ufleisch commentedon May 14, 2021
I had a look at this issue. When I open a file on my internal SSD, the time spent in the destructor is small. However, if I open a file on a USB stick, I can confirm that the time spent in the destructor is above 100ms. Tracking the calls down, it can be seen that most of the time is spent in
fclose(). I can just instrumentcloseFile()in tfilestream.cpp to print the time in us (using#include <sys/time.h>on Linux):If the file is opened in read-only mode,
fclose()is fast. When editing tags, it is possible that it is not known in advance if a file has to be modified. So an idea for improvement could be to always open files in read-only mode (fopen()with moderb) but store the information if a file is allowed to be written and then change the file mode torb+usingfreopen(0, "rb+", d->file)when allowed and necessary, i.e. before a call to thewriteFile()function in tfilestream.cpp. However, I am not sure if this is a good idea, especially the sentencein the
freopenman page makes me doubt.