Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Refactor Context usage for performance #26

Merged
merged 5 commits into from
Jul 10, 2019
Merged

Refactor Context usage for performance #26

merged 5 commits into from
Jul 10, 2019

Conversation

jamesplease
Copy link
Owner

@jamesplease jamesplease commented Jul 10, 2019

Resolves #21

The problem

The old implementation propagated changes through Context. This was problematic in situations where there were a lot of focused nodes: any change to the focus tree would rerender every subscribed component.

I was observing noticeable drops in performance due to this problem.

This solution

In this solution, Context never causes a rerender, because the Context values are always static.

Instead, localized state causes a render. This state is kept in sync using focusTree.subscribe(). To ensure that the fewest number of things render at a time, a comparison check is utilized in the subscribe callback to see if state should be synchronized.

Additional work

It would probably be worthwhile to refactor the Focusable in a more substantial way. Perhaps I'll do that when I work on #25

Alternative solutions

Context selectors is an alternative solution, but as of the time of writing they are only an RFC.

@jamesplease jamesplease merged commit a6615aa into master Jul 10, 2019
@jamesplease jamesplease deleted the perf branch July 10, 2019 19:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Utilize multiple contexts for performance
1 participant