-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Changes to AsyncLocal usage for better lazy loading performance #35835
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
Conversation
@henriquewr I'm not very familiar with that particular part of the code, but async code is executed across different threads - every time the code awaits, it may continue executing on a different thread. So checking the thread ID is probably wrong here - the AsyncLocal is being used to propagate the state across different threads. But I may be misunderstanding things here. @AndriySvyryd assigning this (and #35832) to you as you know the area best. |
I agree with @roji, for recursive lazy loading async calls the thread might change between the outer call and the nested call leading to a deadlock. If the issue is indeed caused by |
and use static AsyncLocal
@AndriySvyryd |
With this approach there still might be a deadlock issue with different lazy loaded navs trying to load the same nav in a nested call, but this use case is probably so rare that we don't need to worry about it. |
Thanks for your contribution! |
@maumar the resulting diff doesn't use ThreadId and this wrong title propagated to net10 release notes. |
Came here from the release notes too |
Corrected the PR title and submitted dotnet/EntityFramework.Docs#5054 to fix the what's new docs. |
Changed AsyncLocal to ThreadId for better performance
Fixes #35832