boostcampwm-2022 / web18-PRV

논문 인용관계를 밤하늘의 별 처럼 표시해보자 🌟-🌟
https://paperef.com
145 stars 3 forks source link

[FE] 배경에 별 깜빡이는 애니매니션 사용시 fps 대폭 감소 #25

Closed yeynii closed 1 year ago

yeynii commented 1 year ago

이슈 내용

StarLayer의 애니매이션이 프레임을 많이 잡아먹어 성능저하가 심합니다.

기대 결과

스크린샷

ezgif-4-8d1b273825 star 300개 찍었을 때

yeynii commented 1 year ago

star 컴포넌트 하나하나에 애니매이션을 걸지않고, star를 여러개 묶은 컴포넌트에 애니매이션을 거는 방식으로 frame rate를 향상시켰습니다.

ezgif-5-9abf3d3e29

JunYupK commented 1 year ago

좋은 해결 방법입니다.

yeynii commented 1 year ago

개선전

    <Container>
      {Array.from({ length: 300 }).map((v, i) => {
        const randomSize = Math.random();
        return (
          <Star
            key={i}
            style={{
              width: `${randomSize * 3 + 1}px`,
              height: `${randomSize * 3 + 1}px`,
              animationDuration: `${Math.random() * 5 + 5}s`,
              animationDelay: `${Math.random() * 5}s`,
              top: `${Math.random() * height}px`,
              left: `${Math.random() * width}px`,
            }}
          >
            <Blur />
          </Star>
        );
      })}
    </Container>

개선후

    <Container>
      {Array.from({ length: 15 }, (_, i) => {
        const randomConstant = Math.random();
        return (
          <Stars
            key={i}
            style={{
              animationDuration: `${randomConstant * 5 + 5}s`,
              animationDelay: `${randomConstant * 5}s`,
            }}
          >
            {Array.from({ length: 20 }, (_, j) => (
              <Star
                key={j}
                style={{
                  width: `${randomConstant * 3 + 1}px`,
                  height: `${randomConstant * 3 + 1}px`,
                  top: `${Math.random() * height}px`,
                  left: `${Math.random() * width}px`,
                }}
              >
                <Blur />
              </Star>
            ))}
          </Stars>
        );
      })}
    </Container>