Poor startup time / hitching on M1 MacBook Air #12

Closed
opened 2023-07-04 21:19:28 +00:00 by bvisness · 5 comments
Owner

On my M1 MacBook Air, my whole computer hitches and freezes when Orca starts up. Even audio freaks out. The app also takes several seconds to initialize in total.

It's a 2020 M1 MacBook Air with macOS 13.3.1 (Ventura).

Here's a spall profile of it starting up. Unfortunately I lack the knowledge to really pinpoint the issue. https://cdn.discordapp.com/attachments/1040279196351614987/1125030418723373176/profile.spall

On my M1 MacBook Air, my whole computer hitches and freezes when Orca starts up. Even audio freaks out. The app also takes several seconds to initialize in total. It's a 2020 M1 MacBook Air with macOS 13.3.1 (Ventura). Here's a spall profile of it starting up. Unfortunately I lack the knowledge to really pinpoint the issue. https://cdn.discordapp.com/attachments/1040279196351614987/1125030418723373176/profile.spall
Collaborator

Could you step in a debugger through the beginning or main() and orca_runloop() and narrow down when the freeze happens?

Could you step in a debugger through the beginning or `main()` and `orca_runloop()` and narrow down when the freeze happens?
Author
Owner

The hitches are occurring in this section:

	for(int i=0; i<3; i++)
	{
		mg_surface_prepare(app->surface);
		mg_canvas_set_current(app->canvas);
		mg_render(app->surface, app->canvas);
		mg_surface_present(app->surface);

		mg_surface_prepare(app->debugOverlay.surface);
		mg_canvas_set_current(app->debugOverlay.canvas);
		mg_render(app->debugOverlay.surface, app->debugOverlay.canvas);
		mg_surface_present(app->debugOverlay.surface);
	}

It's not clear to me that any particular call is the source of the hitches on its own. When I single-step, I don't get any hitches but some calls are sporadically slower. When I skip over the whole loop, it almost always hitches. When I skip from block to block, I sometimes get hitches and sometimes don't...

It feels like the faster I run these, the more likely it is to hitch.

The hitches are occurring in this section: ```cpp for(int i=0; i<3; i++) { mg_surface_prepare(app->surface); mg_canvas_set_current(app->canvas); mg_render(app->surface, app->canvas); mg_surface_present(app->surface); mg_surface_prepare(app->debugOverlay.surface); mg_canvas_set_current(app->debugOverlay.canvas); mg_render(app->debugOverlay.surface, app->debugOverlay.canvas); mg_surface_present(app->debugOverlay.surface); } ``` It's not clear to me that any particular call is the source of the hitches on its own. When I single-step, I don't get any hitches but some calls are sporadically slower. When I skip over the whole loop, it almost always hitches. When I skip from block to block, I sometimes get hitches and sometimes don't... It feels like the faster I run these, the more likely it is to hitch.
Collaborator

yeah, so the reason behind this is that the first time you ask for a metal drawable, it seems to take some time for the system to initialize it, and then metal drawables get recycled and reused (taking much less time).

So I had hitches the first time the debug overlay was opened, and I figured it would be better to just initialize everything at startup and run smoothly afterwards. Obviously this seems to have a way worse effect on your end... what's really weird is that it should maybe stall the process for a bit, but I don't see why it would freeze your whole system?

I don't know of a good way to avoid the first few stalls when asking for drawables though, I'll have to find more info on this.

yeah, so the reason behind this is that the first time you ask for a metal drawable, it seems to take some time for the system to initialize it, and then metal drawables get recycled and reused (taking much less time). So I had hitches the first time the debug overlay was opened, and I figured it would be better to just initialize everything at startup and run smoothly afterwards. Obviously this seems to have a way worse effect on your end... what's really weird is that it should maybe stall the process for a bit, but I don't see why it would freeze your whole system? I don't know of a good way to avoid the first few stalls when asking for drawables though, I'll have to find more info on this.
Author
Owner

The hitching is now gone on my end. However, there is still maybe a 600ms delay between the window opening and the app being interactive. This is no longer a deal-breaker but it would be good to cut this down somehow.

The hitching is now gone on my end. However, there is still maybe a 600ms delay between the window opening and the app being interactive. This is no longer a deal-breaker but it would be good to cut this down somehow.
bvisness added the
macOS
label 2023-09-17 15:00:10 +00:00
Author
Owner

This is pretty good for me now. I'm just gonna close this issue; we can pursue startup performance in more detail later.

This is pretty good for me now. I'm just gonna close this issue; we can pursue startup performance in more detail later.
Sign in to join this conversation.
No Label
macOS
windows
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hmn/orca#12
No description provided.