Simplify the API between factories and construction contexts by moving more logic into InternalContext. #1854
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.
Simplify the API between factories and construction contexts by moving more logic into InternalContext.
Instead of having factories manage a
ConstructionContext
object and call some subset of methods on it, we simplify things into a number of abstract operations onInternalContext
tryStartConstruction
: called when we are starting constructionfinishConstruction
: called when construction is complete, clears the tablefinishConstructionAndSetReference
: called byConstructorInjector
to support member injectors calling back into itclearCurrentReference
: called byConstructorInjector
after member injection is complete.This enables the following optimizations
disableCircularProxies
is set can get away with a singleint[]
to track the set of currently constructing factories and turnfinishConstructionAndSetReference
into a no-opConstructionContext
object and only allocate when we actually construct a proxy.circularFactoryId
). This allows us to create a open-addressed hashtable with integer keys that reduces allocation, hashing and GC overhead.InternalContext
protocol enables some simplifications in the factories which allows to delete an implementationPreviously we would insert
ConstructionContext
objects into the hash table and reuse them if the same factory was used multiple times. This was generally rare, and now we instead remove keys from the table after construction. In theory this means we always perform 2 hash table lookups per construction where the prior approach might only do one. This is true but in general all lookups missed so the prior approach also required 2 lookups (get
andput
).This is an optimization all on its own, but the new simpler protocol will enable more optimizations in a followup.