Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Maximizing Performance: Advanced Strategies for Optimising React Applications

Nidhi Dadiya
March 16, 2024
53

Maximizing Performance: Advanced Strategies for Optimising React Applications

Monthly WTM Meetup - Open for Everyone

Topic Abstract:

In the ever-evolving landscape of web development, optimizing the performance of React applications remains paramount for delivering exceptional user experiences. As we step into 2024, this session delves into advanced strategies and best practices to elevate the performance of React applications to new heights.

Below will be along hands-on demo:

Rendering Optimization
State and Data Management
Code and Bundle Optimization
Component and Resource Loading
Performance Analysis and Tools

Nidhi Dadiya

March 16, 2024
Tweet

Transcript

  1. • Trigger • Initial Render • When the component’s (or

    one of its ancestors’) state has been updated. • Render • Commit 10 How React renders ?
  2. • Rendering must be a pure calculation • Same inputs

    & same outputs • It minds it’s own business 15 Things to consider while Rendering
  3. • User Experience • Higher conversion rates and better user

    retention 18 Why we should Optimise React Website?
  4. • User Experience • Higher conversion rates and better user

    retention • SEO Rank 19 Why we should Optimise React Website?
  5. • User Experience • Higher conversion rates and better user

    retention • SEO Rank • Reduced Costs 20 Why we should Optimise React Website?
  6. • User Experience • Higher conversion rates and better user

    retention • SEO Rank • Reduced Costs • Competitive Advantage 21 Why we should Optimise React Website?
  7. • Excessive re-renders • Unnecessary component updates • Large component

    trees • Ine ff icient data fetching • Slow rendering of lists 25 Few common reasons for slow performance
  8. • Chrome Dev tools • React Dev tools • React

    Pro f iler • Web pack Bundle Analyser • Lighthouse • Many more 27 Tools to identify performance
  9. • Chrome Dev tools • React Dev tools • React

    Pro f iler (supported on v16.5+) • Web pack Bundle Analyser • Lighthouse • Many more 28 Tools to identify performance
  10. • Memoization techniques • React hooks optimisation • Code splitting

    and lazy loading • Server-side rendering (SSR) and static site generation (SSG) • Optimising network requests (e.g., caching, prefetching) • Optimise State Management • Use Keys Correctly • Performance Testing • Reduce DOM Manipulation • Optimise Image Loading • Bundle Optimisation • Virtualisation of List 31 Plan of Action
  11. 36

  12. 37

  13. 39

  14. L: Liskov Substitution Useful in Component Design If B extends

    A, anywhere you use A you should be able to use B. 45
  15. I: Interface Segregation Discard unused/ irrelevant methods Don't make a

    component rely on props it doesn't care about. 46
  16. D: Dependency Inversion High-level code shouldn't depend on implementation details

    always use an abstraction. hide the wiring behind the wall 47
  17. • SOLID principles in React • Prefer functional components over

    class components • Keep state minimal (Use context/ redux for state management) 49 Best practices
  18. • SOLID principles in React • Prefer functional components over

    class components • Keep state minimal (Use context/ redux for state management) • Virtualise Large Lists 50 Best practices
  19. • SOLID principles in React • Prefer functional components over

    class components • Keep state minimal (Use context/ redux for state management) • Virtualise Large Lists • Minimise Third-Party Dependencies 51 Best practices
  20. • SOLID principles in React • Prefer functional components over

    class components • Keep state minimal (Use context/ redux for state management) • Virtualise Large Lists • Minimise Third-Party Dependencies • Optimise Network Requests 52 Best practices
  21. • SOLID principles in React • Prefer functional components over

    class components • Keep state minimal (Use context/ redux for state management) • Virtualise Large Lists • Minimise Third-Party Dependencies • Optimise Network Requests • Optimise Images, Assets, Fonts 53 Best practices
  22. • SOLID principles in React • Prefer functional components over

    class components • Keep state minimal (Use context/ redux for state management) • Virtualise Large Lists • Minimise Third-Party Dependencies • Optimise Network Requests • Optimise Images, Assets, Fonts • Regularly Refactor and Improve 54 Best practices
  23. • SOLID principles in React • Prefer functional components over

    class components • Keep state minimal (Use context/ redux for state management) • Virtualise Large Lists • Minimise Third-Party Dependencies • Optimise Network Requests • Optimise Images, Assets, Fonts • Regularly Refactor and Improve • Always use latest versions 55 Best practices
  24. • SOLID principles in React • Prefer functional components over

    class components • Keep state minimal (Use context/ redux for state management) • Virtualise Large Lists • Minimise Third-Party Dependencies • Optimise Network Requests • Optimise Images, Assets, Fonts • Regularly Refactor and Improve • Always use latest versions • Use Linter 56 Best practices
  25. • Updating state or props unnecessarily • Making too many

    or unnecessary network requests 59 Common Mistakes to Avoid
  26. • Updating state or props unnecessarily • Making too many

    or unnecessary network requests • Overuse of local component state 60 Common Mistakes to Avoid
  27. • Updating state or props unnecessarily • Making too many

    or unnecessary network requests • Overuse of local component state • Overuse of too many third-party libraries 61 Common Mistakes to Avoid
  28. • Updating state or props unnecessarily • Making too many

    or unnecessary network requests • Overuse of local component state • Overuse of too many third-party libraries • Large images and unoptimised assets 62 Common Mistakes to Avoid
  29. • Updating state or props unnecessarily • Making too many

    or unnecessary network requests • Overuse of local component state • Overuse of too many third-party libraries • Large images and unoptimised assets • Large initial bundle size 63 Common Mistakes to Avoid
  30. • Updating state or props unnecessarily • Making too many

    or unnecessary network requests • Overuse of local component state • Overuse of too many third-party libraries • Large images and unoptimised assets • Large initial bundle size • Failing to monitor and analyse performance 64 Common Mistakes to Avoid
  31. • Updating state or props unnecessarily • Making too many

    or unnecessary network requests • Overuse of local component state • Overuse of too many third-party libraries • Large images and unoptimised assets • Large initial bundle size • Failing to monitor and analyse performance • Rendering everything on the client side 65 Common Mistakes to Avoid
  32. • Updating state or props unnecessarily • Making too many

    or unnecessary network requests • Overuse of local component state • Overuse of too many third-party libraries • Large images and unoptimised assets • Large initial bundle size • Failing to monitor and analyse performance • Rendering everything on the client side • Duplicate libraries • Unused code 66 Common Mistakes to Avoid
  33. Advice from Personal Experience: Nidhi “You always know when you’re

    delivering quality or applying a patch. Conquer this feeling to always deliver the best. It might take time to deliver at first but once you make it a habit, trust me you can lower the time you look back at your code for refactoring. ” 67
  34. References • Code splitting: https://www.youtube.com/watch?v=JU6sl_yyZqs • Blog: https://www.freecodecamp.org/news/measure-and-improve- performance-of-react-apps/ •

    Video: https://www.youtube.com/watch?v=CaShN6mCJB0 • Solid principles: https://www.youtube.com/watch?v=Ix6JoarGYiA • Case Study : https://medium.com/dev-channel/a-pinterest-progressive- web-app-performance-case-study-3bd6ed2e6154 72