Giter VIP home page Giter VIP logo

filters-are-a-mess's Introduction

Filters Are A Mess

A performance improvement exercise everyone should try.

The Story

They told me to compose a filter component. These were their requirements:

  • Present given filters + their statuses (checked / unchecked).
  • Filter statuses can be changed on the user session.
  • Filters are applied once apply button is clicked.
  • Apply button should be disabled if no pending changes.
  • Enable “Select All” functionality for quick selection.

And so I've developed the filter component. Everything went well, it was rolled out as planned, and our customers were happy! img.png But than came this huge customer, and ruined it all! My bulletproof filter component failed, and my boss wasn't happy :(

I gave it a go, how hard could it be? The things I've learned when solving the different issues that came up has put me in perspective on what I know about performance.

The Exercise

Given my perfectly fine <FiltersComponent />, find a way to turn it scalable, and support larger amounts of data. Make sure to make any product decisions by your own. The component should look and behave exactly the same from the end-user's perspective.

Installation

git clone [email protected]:poseneror/filters-are-a-mess.git
cd filters-are-a-mess
npm install

Running the project

  1. Start project locally - npm start
  2. Run tests (performance milestones included) - npm test img.png

Goal

Pass as many performance milestones as possible

You can play with the amount of filters drawn by modifying main.tsx

Tips

Sometimes we need to go back to school. Let's re-visit data-structure lectures and try to map big O(n) notations for different operations / calculations we made in the component.
Parents Suck.
  1. A react component re-renders every time its state updates.
  2. A react component will ALWAYS re-render when its parent re-renders.
Memoize your components to prevent re-rendering if props don’t change.
Important: Anonymous functions defined during render cycle have unique references.
Virtualize Long Lists Official React Docs:
"If your application renders long lists of data (hundreds or thousands of rows), we recommend using a technique known as “windowing”. This technique only renders a small subset of your rows at any given time, and can dramatically reduce the time it takes to re-render the components as well as the number of DOM nodes created." There are different ways to virtualize long lists, including infinite scroll, and different pagination methods. But in order to keep the current behavior I found out it's best to use react-window.

Feel Free to share your solutions and results!

filters-are-a-mess's People

Contributors

posener-via avatar poseneror avatar levgou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.