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

[Renderers/Raylib] CPU load is high #293

Open
calvin2021y opened this issue Mar 3, 2025 · 5 comments
Open

[Renderers/Raylib] CPU load is high #293

calvin2021y opened this issue Mar 3, 2025 · 5 comments

Comments

@calvin2021y
Copy link

calvin2021y commented Mar 3, 2025

try build raylib-sidebar-scrolling-container, raylib-multi-context, and SDL3-simple-demo on macOS, the CPU load is around 10% to 70%.

raylib-sidebar-scrolling-container logs:

layout time: 70.566000 microseconds
layout time: 71.361000 microseconds
layout time: 71.475000 microseconds
layout time: 53.544000 microseconds
layout time: 69.166000 microseconds
layout time: 69.181000 microseconds
layout time: 68.377000 microseconds
layout time: 70.511000 microseconds
layout time: 100.101000 microseconds
layout time: 73.889000 microseconds
layout time: 98.027000 microseconds
layout time: 108.022000 microseconds

compare to Microsoft Edge or chrome, to load https://github.com/nicbarker/clay cpu load max around 40%. (browser on background cpu load is about 4%)

I just build them by:

cd clay/examples/SDL2-video-demo
cmake -DCMAKE_BUILD_TYPE=Release . 
cmake --build . --config Release

Is this expected or I do something wrong?

@Ryzee119
Copy link
Contributor

Ryzee119 commented Mar 3, 2025

For me, raylib is rendering as fast as it possibly can. Perhaps try limiting the fps.

add a SetTargetFPS(60); or similar helps alot

@calvin2021y
Copy link
Author

with SetTargetFPS(60), raylib-sidebar-scrolling-container cpu load around 25%, some time 50% if there is some action.

compare the browser cpu load without action, still much higher.

@nicbarker
Copy link
Owner

@calvin2021y Browsers by default won't re render if there is no user input - try watching the CPU usage when you're wiggling your mouse cursor over a page 🙂

Raylib has an equivalent setting you can enable that emulates this behaviour, with EnableEventWaiting();.

You can see that it's commented out in the example raylib renderer here: https://github.com/nicbarker/clay/blob/main/renderers/raylib/clay_renderer_raylib.c#L122

@nicbarker nicbarker changed the title CPU load is high [Renderers/Raylib] CPU load is high Mar 3, 2025
@hexmaster111
Copy link

#298 May help a little.

@calvin2021y
Copy link
Author

calvin2021y commented Mar 4, 2025

thanks a lot for the tips.

after apply #298 and enable EnableEventWaiting(), build with lto. the cpu load is 5% ~ 20%. in background less than 1%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants