Use a variable sized thread pool in AssetManager #5153
+2
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the version of this patch targeting 1.16, for the version targeting 1.17 see #5151
Identify the Bug or Feature request
fixes #4962
Description of the Change
AssetManager has a thread pool for loading assets that prevents the network handler thread from blocking when it receives a message that requires an asset load.
It is a single thread, which effectively serialises loading.
Unfortunately this means that if the appropriate action after loading an asset is to load a subsequent asset (such as AddOns loading the onInit script in order to run them when the AddOn has been loaded) then this deadlocks.
If the asset is not already cached then instead of the load callbacks being called in the loader thread the assetLoader class' thread pool handles the callbacks, so it should be safe to use a larger thread pool to load assets.
This patch switches the single thread pool with a reference to the
ForkJoinPool.commonPool()
which is used by CompletableFutures as the "default" thread pool.Possible Drawbacks
Supporting parallel loading of assets could potentially have observable changes that cause other bugs, but there are circumstances already that allow assets to load in parallel, so these code paths aren't untested.
Release Notes
This change is