Refactor the standard role editor to optimize its performance #50871
+751
−247
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 change makes every role editor section render separately, not affecting other sections. This allows us to scale to a large number of access rules and resource sections without causing UI lag.
The optimization is achieved by UI component property memoization. In order to do it, we switch from managing the standard editor state using
useState()
touseReducer()
. The state and action dispatcher are created with a newuseStandardModel()
function. This allows us to pass around a stable dispatcher reference instead of individual callbacks, which at some level had to depend on some top-level state.Another change required to support memoization in the rendering phase is memoizing partial validation results.
The optimizations were verified using the React profiler and making sure that changing one section doesn't cause rendering others.
No user-visible changes expected, apart from a snappier UI (best tested with a 6x CPU throttling, if you have a beast of a machine).