hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
10.99k stars 657 forks source link

audio/internal/readerdriver: Locking/unlocking by mutexes takes a little long time on Windows #1652

Closed hajimehoshi closed 3 years ago

hajimehoshi commented 3 years ago

Measured CPU profiling with an application that plays a music:

Showing top 10 nodes out of 30
      flat  flat%   sum%        cum   cum%
     1.05s 50.48% 50.48%      1.05s 50.48%  runtime.cgocall
     0.47s 22.60% 73.08%      0.47s 22.60%  sync.(*Mutex).Lock
     0.29s 13.94% 87.02%      0.29s 13.94%  sync.(*Mutex).Unlock
     0.14s  6.73% 93.75%      0.21s 10.10%  github.com/hajimehoshi/ebiten/v2/audio/internal/readerdriver.(*players).readAndWriteBuffers
     0.07s  3.37% 97.12%      1.04s 50.00%  github.com/hajimehoshi/ebiten/v2/audio/internal/readerdriver.(*players).loop
     0.03s  1.44% 98.56%      0.03s  1.44%  github.com/hajimehoshi/ebiten/v2/audio/internal/readerdriver.(*header).IsQueued
     0.01s  0.48% 99.04%      0.02s  0.96%  github.com/jfreymuth/vorbis.(*Decoder).decodePacket
         0     0% 99.04%      1.03s 49.52%  github.com/hajimehoshi/ebiten/v2.RunGame
         0     0% 99.04%      0.02s  0.96%  github.com/hajimehoshi/ebiten/v2/audio.(*InfiniteLoop).Read
         0     0% 99.04%      0.02s  0.96%  github.com/hajimehoshi/ebiten/v2/audio.(*timeStream).Read

image

hajimehoshi commented 3 years ago
Showing top 10 nodes out of 23
      flat  flat%   sum%        cum   cum%
     2.09s 49.88% 49.88%      2.09s 49.88%  runtime.cgocall
     0.77s 18.38% 68.26%      0.92s 21.96%  runtime.mapiternext
     0.33s  7.88% 76.13%      0.33s  7.88%  sync.(*Mutex).Lock
     0.25s  5.97% 82.10%      0.25s  5.97%  sync.(*Mutex).Unlock
     0.23s  5.49% 87.59%      2.10s 50.12%  github.com/hajimehoshi/ebiten/v2/audio/internal/readerdriver.(*players).loop
     0.15s  3.58% 91.17%      0.84s 20.05%  runtime.mapiterinit
     0.11s  2.63% 93.79%      0.20s  4.77%  github.com/hajimehoshi/ebiten/v2/audio/internal/readerdriver.(*players).readAndWriteBuffers
     0.08s  1.91% 95.70%      0.08s  1.91%  runtime.isEmpty (inline)
     0.05s  1.19% 96.90%      0.05s  1.19%  github.com/hajimehoshi/ebiten/v2/audio/internal/readerdriver.(*header).IsQueued (inline)
     0.04s  0.95% 97.85%      0.04s  0.95%  runtime.add
hajimehoshi commented 3 years ago

Now this is resolved after a new implementation with multiple waveOutOpen.

Showing top 10 nodes out of 35
      flat  flat%   sum%        cum   cum%
     1.31s 98.50% 98.50%      1.31s 98.50%  runtime.cgocall
     0.01s  0.75% 99.25%      0.01s  0.75%  github.com/jfreymuth/vorbis.(*bitReader).Read1 (inline)
     0.01s  0.75%   100%      0.01s  0.75%  github.com/jfreymuth/vorbis.renderLine
         0     0%   100%      1.28s 96.24%  github.com/hajimehoshi/ebiten/v2.RunGame
         0     0%   100%      0.02s  1.50%  github.com/hajimehoshi/ebiten/v2/audio.(*InfiniteLoop).Read
         0     0%   100%      0.02s  1.50%  github.com/hajimehoshi/ebiten/v2/audio.(*timeStream).Read
         0     0%   100%      0.02s  1.50%  github.com/hajimehoshi/ebiten/v2/audio/internal/convert.(*f32Reader).Read
         0     0%   100%      0.03s  2.26%  github.com/hajimehoshi/ebiten/v2/audio/internal/readerdriver.(*header).Write
         0     0%   100%      0.05s  3.76%  github.com/hajimehoshi/ebiten/v2/audio/internal/readerdriver.(*playerImpl).readAndWriteBuffer
         0     0%   100%      0.05s  3.76%  github.com/hajimehoshi/ebiten/v2/audio/internal/readerdriver.(*playerImpl).readAndWriteBufferImpl