-
-
Notifications
You must be signed in to change notification settings - Fork 23.8k
Rationalize busy waits #98385
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
Rationalize busy waits #98385
Conversation
|
Yield has really poor performance on macOS. The function gets compiled down to sched_yield, which can yield the process to other processes running on the system. Lack of SIMT also means you can't yield work to other threads. |
affd1de to
63e0f96
Compare
5c16dcb to
329e0f5
Compare
|
I've added a special implementation for Apple platforms. |
|
Thanks for looking into making changes. Unfortunately, pthread_yield_np also messed with thread priorities :( There's not really a good option, but you're better off spinning and burning cycles rather than yielding. Ideally you could use os_unfair_lock to let the scheduler know what thread another thread is waiting on. |
I don't think busy waiting is needed or even appropriate in any of these cases (except maybe editor_log if it's invoked by multiple threads). May I ask why this code isn't using a semaphore or condition variable or similar mechanism? |
329e0f5 to
17fca1a
Compare
|
@mrsaturnsan, good point. I was misinformed that @lyuma, you'be brought the greatest sanity here. Please check the updated description. |
clayjohn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code and the approach look good to me, but I am not an expert in this area so TIWAGOS
|
cc @adamscott regarding HTTPRequest in threaded mode. Will this be an issue on the web platform? |
|
I got this Either:
cc. @Faless |
|
Wow, that check comes from seven years ago!: #16781. Back them, HTTP requests on the web were backed by |
|
CC @Faless |
|
I'm gonna check this out. |
Just realized that HTTPRequest in threaded mode isn't compatible with the Web platform at all (we cannot |
17fca1a to
4f8dd96
Compare
|
Since we're too slow in coming up with a consensus on the |
|
@lyuma Please take another look if you can, so we can get this merged. |
|
Thanks! |
Using the yield primitive lets the OS know our intent better than a microwait. This may improve energy efficiency and/or performance.2024-10-31:
@lyuma's comment about the specific cases made me realize we don't even need to discuss how to implement a yield mechanism, since there's no real need for that.
So, I've updated the PR addressing each case of
delay_usec(1)in loops:EditorFileSystem: It was used to poll for the status of the batched import. I've overhauled it so a semaphore controls it instead.EditogLog: I've added a non-polling sync mechanism toRichTextLabel. (By the way,RichTextLabelthreading warrants further threading improvements, but that's out of the scope of this PR.)EditorNode::immediate_confirmation_dialog(),EditorFileSystemImportFormatSupportQueryBlend: They are already using main loop iterations, so pacing is implicit.HTTPRequest: In threaded mode, it uses blocking sockets, so the loop isn't really going to run freely. Therefore, I've just removed the relevant call. (Is blocking not supported somewhere?)