-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
cpu usage #111
Comments
CPU usage is between 300% and 400% for me with the simplest examples (button, sprite...) EDIT: Using Mint 20 on Linux 5.4 on Intel i7-8705G and dual video card Radeon RX Vega M GL + HD Graphics 630 |
I confirm this. |
@coolit @joseluis @martin-fl What operating systems, hardware, and render backend do you all use? |
@skreborn |
I have anywhere between 50% and 70% usage on Windows 10 with an Intel® Core™ i7-9750H CPU @ 2.60GHz × 12 and an NVIDIA GeForce RTX 2080 Max-Q for It's worth noting that release mode reduces that to slightly above 30%. |
Compiling in release mode does in fact reduce CPU usage to ~10% on the |
Release mode had the sprite example running at around 30% for me, based on htop. Bit disappointing such a simple example isn't performant, but the library looks like a great start so I feel silly even making the complaint. I figure this will be fixed quickly. here is a flamegraph, hopefully it's helpful |
I expect there to be a ton of low hanging fruit when it comes to optimization. So far the focus has been on api surface and building solid foundations. For example, right now Bevy is way more hash-ey per-frame than I would like it to be. We can fix most of the CPU getting eaten there by using the new "change detection" features in Bevy ECS. On top of that, I think some persistent CPU usage is expected, as we (currently) use rayon under the hood and other projects have encountered similar behavior. I think the most important metric bevy can optimize is frame_time (which you can measure by adding the This is the sort of issue that will never fully be resolved. There will always optimization work to do. I am inclined to close this issue (and reference it whenever a new one comes up). Feel free to open issues for specific cases where you have isolated slow parts of Bevy. (also i wont close this for a small period of time. feel free to respond here with rationale if you think leaving this open is better) |
This is a problem with rayon. The more cores you have, the more CPU you burn. My 3950x pins the CPU at 100% in the window_settings example. I've seen this behavior on several projects that use rayon. |
As a workaround for anyone having an unpleasant time with this, you can use the environment variable RAYON_NUM_THREADS to limit the number of threads. I would recommend anyone with more than 8 cores set it to something <=8. Just to be clear, this isn't "bevy is using a lot of CPU" it's "rayon doesn't properly idle threads that have no work to do". A 32 logical core CPU will pin at 100%, but when forced to use 8 logical cores, will run at about 13% utilization (despite that being 25% of the cores). That is still higher than it ought to be. I don't think bevy's examples generate enough workload to justify saturating multiple cores. |
Would something like Unity's |
that's probably fixed by rayon-rs/rayon#746 |
Rayon 1.4.0 has been released with the fix! rayon-rs/rayon#784 Release notes - "Implemented a new thread scheduler, RFC 5, which uses targeted wakeups for new work and for notifications of completed stolen work, reducing wasteful CPU usage in idle threads." |
I ran the breakout example on my old quadcore machine using master and also using master + rayon bumped to 1.4. Both were run in release mode: Master CPU usage: 220% Huge improvement but still extremely high for only rendering a few rectangles. Hope to see even more improvements in the future! 🎉 |
The extreme CPU usage requires more than 4 cores to reproduce. I roughly reproduce your results if forcing RAYON_NUM_THREADS=4 On a 3950x (32 cores) using Bevy 0.1.3: I saw no difference with rayon 1.4: Moving to the new task system I get: (For whatever reason I'm not seeing the all-cores-100% I was seeing the other night but I've seen it in other projects using rayon.) |
The new task system (to replace Rayon) was just merged in #384 |
Can anybody previously experiencing high CPU usage testify the new task system fixes this issue? |
I will test it out on my work computer (the one I ran it on before) in about 9 hours. |
Examples no longer saturate all cores on my computer. They use far less than a single core now. Seems good to me on mac. 👍 |
Alrighty I think that's enough evidence to close this out. CPU usage will always be a moving target and there's still plenty of optimization potential, but we've made enough progress here that I think we can move from "generic CPU usage issue" to "specific issues for specific optimization cases". |
more trace cleanup: remove some references to stage
e.g. In the "button" example, sometimes the cpu usage is about 10-20% in release mode, which is relatively high.
Is there any plan for future improvement? Thanks.
edit: I used win10, Intel 2.40GHz.
The text was updated successfully, but these errors were encountered: