Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slowness in delegate page #180

Merged
merged 4 commits into from
Oct 7, 2024
Merged

Fix slowness in delegate page #180

merged 4 commits into from
Oct 7, 2024

Conversation

Tbaut
Copy link
Contributor

@Tbaut Tbaut commented Oct 5, 2024

closes #151

Copy link

cloudflare-workers-and-pages bot commented Oct 5, 2024

Deploying delegit with  Cloudflare Pages  Cloudflare Pages

Latest commit: 678d8ff
Status: ✅  Deploy successful!
Preview URL: https://4a069181.delegit.pages.dev
Branch Preview URL: https://tbaut-usecallbacks.delegit.pages.dev

View logs

@Tbaut Tbaut marked this pull request as ready for review October 5, 2024 23:18
@Tbaut Tbaut requested a review from wirednkod as a code owner October 5, 2024 23:18
@Tbaut
Copy link
Contributor Author

Tbaut commented Oct 5, 2024

The main issue was

  • rendering of the modal even when not needed. I added a condition there.
  • many complex functions re-rendering, the heaviest was isExhaustedRessources, it's much better now with useMemo

If you type in the input now, it's instant. Before it took a sec for the text to appear.

@Tbaut Tbaut changed the title Fix some slowness Fix slowness in delegate page Oct 5, 2024
src/header.tsx Outdated Show resolved Hide resolved
src/header.tsx Outdated Show resolved Hide resolved
src/header.tsx Outdated Show resolved Hide resolved
aliceKeyPair.publicKey,
'Sr25519',
aliceKeyPair.sign,
const aliceKeyPair = useMemo(() => derive('//Alice'), [derive])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand this... derive (line 14) already uses useMemo. Why to reuse it?

Copy link
Contributor Author

@Tbaut Tbaut Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we don't need to derive every single render if derive doesn't change. So the aliceKeyPair will be derived once for all. Also I just memoize / useCallback everything at this point. Spending an hour to find the one function that makes everything slow is more time consuming than bluntly memoizing every single const IMHO. I used to do this in all my apps, chose not to be annoying for Delegit, and it bit us all the same. The experience of using the delegate page just got much much better thanks to this.

src/pages/Delegate/index.tsx Outdated Show resolved Hide resolved
src/pages/Delegate/index.tsx Outdated Show resolved Hide resolved
src/pages/Delegate/index.tsx Outdated Show resolved Hide resolved
@Tbaut Tbaut requested a review from wirednkod October 7, 2024 08:43
@Tbaut
Copy link
Contributor Author

Tbaut commented Oct 7, 2024

Thanks for the review, and sorry for the 1000 oversights of logs etc 😅

@wirednkod wirednkod merged commit 0170c6e into main Oct 7, 2024
3 checks passed
@wirednkod wirednkod deleted the tbaut-usecallbacks branch October 7, 2024 08:44
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.

Something is super slow when clicking on delegate..
2 participants