Comments (14)
Not anywhere as bad on my desktop Win10 machine though... Just under 5 sec overall
However if we compare with MidiSharp-based example (with my patch f3flight/MidiSharp@a7614bd), the results are:
So it's about 200 times faster...
I wonder if we can make DryWetMidi anywhere as fast...
from drywetmidi.
Specifically slow items are these two lines:
if (!tempoChanges.Any())
foreach (var tempoChange in tempoChanges.Concat(new[] { new ValueChange<Tempo>(time, tempoLine.AtTime(time)) }))
from drywetmidi.
I made an improvement, let me make a pull request..
from drywetmidi.
with this change I get down to ~1.8s in Release profiling:
without it I get around ~2.8s
from drywetmidi.
it's interesting that after this patch, allocating doubles is slow... whaat?
I'll see if I can improve performance further...
from drywetmidi.
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.
@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.
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.
@melanchall sounds great! cant wait to see it implemented, i will then move forward with my project using your lib.
from drywetmidi.
from drywetmidi.
@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.
@melanchall I confirm significant (~10x) speed up achieved, thank you very much for this improvement.
from drywetmidi.
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.
I guess so, thank you!
from drywetmidi.
Related Issues (20)
- HELP !!! Notes in panel to midi file?? HOT 9
- please help a noob HOT 6
- Remove all notes example from the README not working HOT 9
- Using wetdrymidi in C# project causes error CS0009
- InputDevice event listening crash HOT 2
- Crash when running in Unity on M2 MacBook HOT 3
- MidiDeviceException Internal error HOT 9
- Android Support
- Unity cannot exit after use HOT 10
- MidiClock sync problem HOT 6
- MIDI Tempo changes count returns 1 but the song has 6 tempo changes. HOT 1
- add il2cpp mode HOT 5
- CustomChunk no mididata throw error HOT 4
- CSharp Code Error HOT 2
- MIDI File returns error: InvalidMetaEventParameterValueException HOT 1
- Unable to send Note-On event to device HOT 8
- Cannot get track name to change HOT 10
- How to use DryWetMidi in Visual Basic (VS 2022) ? HOT 20
- Plans for MIDI 2.0 Support? HOT 2
- Skipping notes HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drywetmidi.