Synchronize, optimize, and safely delay native module load #536
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.
Goal
The SharedObjectLoader module tried to load the module into memory every time it is called, but it's not necessary when it's already been done on a process.
Optimize this by saving the successful loading value and returning true to indicate that it's load without first doing a reload.
Also, make the runtime dependency more explicit as components were relying on the loading having before the init, which meant it was doing it way too soon.
Further, synchronize that method so we don't do if more than once. Once it's loaded, the synchronization block won't be hit so this is really impacts the the pre-init workflows that hit this, which are PLENTY, though this PR will not improve that, as this is meant to be minimally invasive only.
Testing
Modify existing tests. We could probably improve them though as they are based on mocks happening at a higher level, and no unit tests exist for this component by itself, as it relies on being tested via its usages.