Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance in multiple areas #115

Closed
VGMRUS opened this issue Jun 28, 2022 · 11 comments
Closed

Improve performance in multiple areas #115

VGMRUS opened this issue Jun 28, 2022 · 11 comments
Labels
bug Something isn't working or is incorrect
Projects

Comments

@VGMRUS
Copy link

VGMRUS commented Jun 28, 2022

Describe the bug
A clear and concise description of what the bug is.
The enhanced shadows REALLY need some optimization, specially with high amounts of instruments showing up at once.

I have a RX580 4gb (and ryzen 3700x), and it is struggling to get to 60fps and sometimes even 30fps and with enough instruments not even 15fps with the shadows at low (doesn't change the performance much with medium and high shadows).

If I put the enhanced shadows on OFF it runs 144fps easily, so these shadows are really slowing down the performance and they should be optimized

IDK if it's because this RX580 is a AMD card and amd card windows drivers are NOTORIOUS for bad OpenGL performance compared with nvidia or even intel, if midis2jam2 is using OpenGL that could be a factor and adding vulkan support would fix it

Offending MIDI file
Upload the MIDI file that causes the bug here.
Any midi with more than 10-20 instruments or more showing up at once really, compare the performance on the same midi with shadows off vs shadows on low/medium/high)

Expected behavior
A clear and concise description of what you expected to happen.
The drop of FPS shouldn't be as big just from shadows on an rx580 mid end card, this card should be more than enough to run midis2jam2 at more than 60fps all the time

System
Provide your OS, and computer specs if applicable.
windows 10 21H2, 2x8gb of ddr4 2666mhz, ryzen 3700x, rx 580 4gb

@VGMRUS VGMRUS added the bug Something isn't working or is incorrect label Jun 28, 2022
@wyskoj
Copy link
Owner

wyskoj commented Jun 28, 2022

Open Task Manager and start a MIDI file. Does your GPU show any usage? Here's what mine looks like (the last column is GPU usage):
image

@wyskoj
Copy link
Owner

wyskoj commented Jun 28, 2022

As far as "optimization" goes, there's not much I can do. I don't manage any of the rendering and graphics component of the application. That's all on jMonkeyEngine and I just use that to create the graphics. My guess is with a graphics card that nice and you are getting shitty performance, it's just not being utilized since it's AMD.

@VGMRUS
Copy link
Author

VGMRUS commented Jun 29, 2022

Not that high gpus usage actually:
the first sixth midijam wasn't open, after that it was
I've just noticed the instrument that decrease the fps the most are the pianos, 2-4 or more pianos really decrease the performance
max total cpu usage I've seen is 8%, when looking at the per thread cpu usage it uses like 2 threads at max usage in each thread at like 50%-60% usage max on each of those threads
imagen
Cheers

@VGMRUS
Copy link
Author

VGMRUS commented Jun 29, 2022

Here in this scene you can see how it only makes 20fps with shadows on low
Here's the midi if you want to compare: Back to the Future II Round 2-1 SNES Official.zip imagen

@wyskoj
Copy link
Owner

wyskoj commented Jun 29, 2022

Can you also open that file again, press F3, and take a screenshot please?

@wyskoj
Copy link
Owner

wyskoj commented Jun 29, 2022

I'm testing it out now and I notice I'm getting only about 30-45 fps myself, so you are right with regard to the frame drop. I will spend some time trying to find the root cause of it.

wyskoj added a commit that referenced this issue Jun 29, 2022
After performing some profiling, I noticed the call to
Sequencer.microsecondLength was taking a considerable amount of time
per frame, thereby reducing the average FPS. To resolve this, the value
is now calculated lazily--since the length never changes, this should be
safe.

While this is not a direct "end all be all" solution to #115, I can only
imagine that this contributes to the problem presented in that issue,
since it does directly relate to the overall performance of the program.
@VGMRUS
Copy link
Author

VGMRUS commented Jun 29, 2022

Sure imagen

@wyskoj wyskoj added this to In progress in v1.7.0 Jun 30, 2022
@wyskoj
Copy link
Owner

wyskoj commented Sep 26, 2022

I've determined the root cause of this slow down is a combination of both many on-screen objects and my event collection system. During the past month or so, I've been doing an entire refactor of the event collection system. My initial implementation that has been used up to this point is pretty naïve and causes lagging when scaled up (many instruments). So it is a contributing factor to the reason why this MIDI file slows down (particularly, the pitch bend control for each instrument is taking a considerable amount of frame time).

I still have some work to do until it is entirely refactored, but I am close. I have changed the logic of almost every instrument to use this new method. So here is what remains that needs to be refactored:

  • Music box
  • Harp
  • Visibility calculations (for all instruments)
  • Pitch bend calculations (for applicable instruments)

This new system I'm developing also supports seeking (jumping around the file) so this is also related to #98.

Hopefully when I have the event collection refactored, it will only be a factor of the performance of the graphics card (or at least a less significant factor).

@wyskoj wyskoj changed the title Enhanced Shadows Need Optimization Refactor event collection system to reduce overhead Sep 26, 2022
@wyskoj
Copy link
Owner

wyskoj commented Oct 4, 2022

I also just found out that the SSAOFilter (screen space ambient occlusion) was adding a lot of extra overhead! Gonna try to tweak this to improve its perfomance.

wyskoj added a commit that referenced this issue Oct 8, 2022
Improves performance significantly!!

Contributes to #115
@wyskoj wyskoj changed the title Refactor event collection system to reduce overhead Improve performance in multiple areas Oct 9, 2022
wyskoj added a commit that referenced this issue Oct 9, 2022
It was adding a substantial amount of overhead loading a 6000x6000
texture, I only did this previously because I didn't want it to be
smoothened, but now it is actually being loaded nearest-neighbor.

Contributes to #115
@wyskoj
Copy link
Owner

wyskoj commented Feb 10, 2024

At this point I've entirely refactored the event collection system. Performance, as it relates to the computation of animation—not necessarily rendering, although that has been optimized and is configurable—has been significantly optimized.

@wyskoj wyskoj closed this as completed Feb 10, 2024
@wyskoj
Copy link
Owner

wyskoj commented Feb 19, 2024

Here in this scene you can see how it only makes 20fps with shadows on low

This MIDI file runs at a smooth 60 FPS now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working or is incorrect
Projects
No open projects
v1.7.0
In progress
Development

No branches or pull requests

2 participants