Cache block item constructors for block based editors #15264
Merged
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.
Prerequisites
Description
When block based editors construct their published values, they use a whole lot of reflection and on-the-fly IL generated types to construct their contained block items. In short, they activate a lot of what's going on in
ReflectionUtilities
.Unfortunately the reflected results are not cached between requests, even though they can never differ as they are type bound. In fact, the results are not even cached between block based editors, so if two block based editors exist on the same page one or more of the same block types, the reflection is repeated for each editor. This also even applies to nested block editors.
The block editors do cache their published values, but all this reflection will still happen for each "first page render" (and after a page publish). The result is a fair amount of CPU time spent churning reflection:
This PR aims to cache as much of this reflection as possible, so we don't have to do all of this reflection over and over.
Since block items are typed to the individual block based editors, caches must be introduced and isolated for each of them (
BlockListItem<TContent, TSettings>
,BlockGridItem<TContent, TSettings>
andRichTextBlockItem<TContent, TSettings>
respectively).Testing this PR
To test this PR, we must ensure that the Block List, the Block Grid and the Rich Text Editor all continue to work the same for their contained blocks. This means they must work:
...and probably a few other permutations.
It might be best to reach out to @kjac for testing 😆