Giter Club home page Giter Club logo

Comments (14)

f3flight avatar f3flight commented on July 19, 2024

Not anywhere as bad on my desktop Win10 machine though... Just under 5 sec overall
image
However if we compare with MidiSharp-based example (with my patch f3flight/MidiSharp@a7614bd), the results are:
image
So it's about 200 times faster...
I wonder if we can make DryWetMidi anywhere as fast...

from drywetmidi.

f3flight avatar f3flight commented on July 19, 2024

Specifically slow items are these two lines:
image

  • if (!tempoChanges.Any())
  • foreach (var tempoChange in tempoChanges.Concat(new[] { new ValueChange<Tempo>(time, tempoLine.AtTime(time)) }))

from drywetmidi.

f3flight avatar f3flight commented on July 19, 2024

I made an improvement, let me make a pull request..

from drywetmidi.

f3flight avatar f3flight commented on July 19, 2024

with this change I get down to ~1.8s in Release profiling:
image
without it I get around ~2.8s
image

from drywetmidi.

f3flight avatar f3flight commented on July 19, 2024

it's interesting that after this patch, allocating doubles is slow... whaat?
image
I'll see if I can improve performance further...

from drywetmidi.

f3flight avatar f3flight commented on July 19, 2024

I guess it's just the whole design around IEnumerables which is progressively slower with each added layer of complexity over source data... So getting anywhere near the MidiSharp's result is unlikely without using some sort of cache...

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

@f3flight Thanks for opening the issue. I am concerned about performance and planning to do some improvements in future releases.

You are right, we need sort of cache to store accumulated microseconds at points of tempo change. I'll think about possible solutions. Maybe I'll introduce something like ITempoMapCache with different implementations for each type of time span and also introduce conversion methods that take that cache instead of TempoMap.

Thanks for pull request, I'll look into it as soon as possible.

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

I tested caching and performed benchmarks with this code:

foreach (var e in _timedEvents)
{
    var mt = e.TimeAs<MetricTimeSpan>(_tempoMap);
}

Results:
without caching ~3.970 s
with caching ~183.5 ms

So yes, cache gives significant performance boost.

from drywetmidi.

f3flight avatar f3flight commented on July 19, 2024

@melanchall sounds great! cant wait to see it implemented, i will then move forward with my project using your lib.

from drywetmidi.

mjbath avatar mjbath commented on July 19, 2024

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

@f3flight I've implemented caching for metric time span conversion (I forgot about linking to an issue inside a commit message so the commit is b008c6c). For this task I've created benchmarks that were ran on this environment:

BenchmarkDotNet=v0.10.12, OS=Windows 10.0.17134
Intel Core i5-7200U CPU 2.50GHz (Kaby Lake), 1 CPU, 4 logical cores and 2 physical cores
Frequency=2648438 Hz, Resolution=377.5810 ns, Timer=TSC
  [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3101.0
  Clr    : .NET Framework 4.7 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3101.0

Results are:

Conversion Mean (without cache, ms) Mean (with cache, ms)
Time from ticks to metric 1320.3 59.12
Length from ticks to metric 2640.3 116.50
Time from metric to ticks 528.7 58.21
Length from metric to ticks 1834.8 118.51

There is no any new public API, caching works internally with regular TempoMap so you don't need to change anything in your code that uses DryWetMIDI.

As you can see from the commit I've created benchmarks for every time span, but note that at the moment performance is improved only for MetricTimeSpan conversion. In fact BarBeatTimeSpan conversion is extremely slow on large collections of events or notes too. It will be handled in another commit, so please don't close the issue.

Please take the latest version of the develop branch and verify that metric conversion is faster now. I'm waiting for your results.

from drywetmidi.

f3flight avatar f3flight commented on July 19, 2024

@melanchall I confirm significant (~10x) speed up achieved, thank you very much for this improvement.

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

The main problem was TempoMap.Tempo.Values and TempoMap.TimeSignature.Values were resorted on every get. So values sorting was performed for each time/length conversion. I eliminated unnecessary sortings and benchmarks results for bar/beat time span conversion are:

Conversion Mean (old, ms) Mean (new, ms)
Time from ticks to bar/beat 972.5 189.7
Length from ticks to bar/beat 1159.1 167.3
Time from bar/beat to ticks 1133.9 192.3
Length from bar/beat to ticks 1610.2 228.5

@f3flight Can the issue be closed?

from drywetmidi.

f3flight avatar f3flight commented on July 19, 2024

I guess so, thank you!

from drywetmidi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.