Yikai-Liao / symusic

A cross platform note level midi decoding library with lightening speed, based on minimidi.
https://yikai-liao.github.io/symusic/
MIT License
108 stars 8 forks source link

[Question] Performance improvement compared to mido #20

Closed leleogere closed 5 months ago

leleogere commented 5 months ago

Hello,

What is the real performance improvement factor compared to mido? I see 100x in the first sentence of the README, but 1021x in the last table of the README. Are those values designing different things?

Thank you for your work, this library seems very promising!

Yikai-Liao commented 5 months ago

It's a good question.

The key problem is that, midi files always tend to be small. And the portion of time consumed on finding the file on your disk increases as the midi file getting smaller.

Well, this part of time is not even a problem for mido, because parsing the file costs far more time. However, we use a number of tricks to optimize the parsing speed. Therefore, although we use fread (not the slow iostream), finding file now consumed a large percentage of the total time.

A similar issue is found when @ilya16 tyied to get his own benchmark in #17.

Since mahler.mid is quite a large midi file (about 600KB), it can still reflect the actual decoding speed (nearly 1000 times faster).

But for real world dataset with relative small files, it would be about 300 times faster in total (reading and parsing the file). Benchmark on these files could found in Natooz/MidiTok#112

Maestro MMD POP909
Symusic 1.94 ± 1.87 ms 0.55 ± 0.59 ms 0.26 ± 0.06 ms
MidiToolkit 0.62 ± 0.54 sec 0.20 ± 0.21 sec 0.11 ± 0.03 sec
Pretty MIDI 0.62 ± 0.55 sec 0.20 ± 0.21 sec 0.11 ± 0.03 sec

Well, for the first sentence of the README, it just means, at least 100 times faster for any kind of situations. Maybe I should change the description now. Do you have any suggestion about this description?

leleogere commented 5 months ago

Okay it makes sense! I don't know if changing the numbers in the README is necessary, but maybe a sentence somewhere specifying why there is a difference between them could be useful! At first read, I thought that there were a typo either in the table or in the first sentence.

Yikai-Liao commented 5 months ago

I have changed the README, it's more clear now

leleogere commented 5 months ago

Simple and clear, perfect!