Skip to content

Optimize hooks a little#4

Open
JanBaryla wants to merge 5 commits intomainfrom
optimize-hooks-a-little
Open

Optimize hooks a little#4
JanBaryla wants to merge 5 commits intomainfrom
optimize-hooks-a-little

Conversation

@JanBaryla
Copy link
Copy Markdown

@JanBaryla JanBaryla commented Mar 14, 2022

Overview

This is a tricky one because I don't know if it 100% works.

Basically the premise is to do two things:

  1. Remove the setTimeout logic out of useCoordinates and move it to the apply wrapper. Thanks to that, way less time is spent just waiting for the timeout to happen.
  2. Introduce a new useAreCoordinatesSelected hook to mitigate the need to run heavy comparison for every cell click in useCellIsSelected. Now it's going to return a boolean and should make things quicker for larger tables.

Risks

Point 1. is the risk-prone one. I've experimented with a couple of possible solutions, including using lodash.debounce instead of setTimeout, but then I ended up at what's in the PR and it still worked, so I stayed with that. I have not seen it do anything weird but then again, testing npm packages locally isn't an easy task.

If we vote against Point 1, Point 2 definitely seems like an easy win, and I'd be happy to cherry-pick just that change.

Testing

See if coordinates stay updated. Monitor the speed of useCellIsSelected.

@JanBaryla JanBaryla requested a review from MichaelDarr March 14, 2022 13:36
@JanBaryla JanBaryla force-pushed the optimize-hooks-a-little branch from ed33774 to 9112b57 Compare March 14, 2022 14:25
@MichaelDarr
Copy link
Copy Markdown
Contributor

This looks really promising. I'm going to push a couple stylistic changes and do some testing, and maybe we can get this through!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants