AtCoderProblems icon indicating copy to clipboard operation
AtCoderProblems copied to clipboard

Improve Responsiveness for Contest Table

Open southball opened this issue 5 years ago • 1 comments

ContestTable の "Show Rating" ボタンは Estimated Performance に影響しないはずですが、"Show Rating" を押すと Estimated Performance の計算が行われて、ちょっと時間かかります。

例:このコンテスト

React の Profiler で時間が見えます(~500 ms です)。

image

Estimated Performance を何 cache すればかなり速くなります。

image

+  const performanceMap = React.useMemo(() => {
     const performanceMap = new Map<UserId, number>();
     if (showEstimatedPerformances) {
       const participantsRawRatings = [] as number[];
@@ -159,6 +160,13 @@ const InnerContestTable: React.FC<InnerProps> = (props) => {
         performanceMap.set(userId, performance);
       }
     }
+    return performanceMap;
+    // eslint-disable-next-line react-hooks/exhaustive-deps
+  }, [
+    JSON.stringify(sortedUserIds), // eslint-disable-line react-hooks/exhaustive-deps
+    JSON.stringify(ratingMap), // eslint-disable-line react-hooks/exhaustive-deps
+    showEstimatedPerformances,
+  ]);

この PR 作ってもいいんですか?

southball avatar Aug 21 '20 11:08 southball

500ms なら放置でいいかな、と思います。

"Show Rating" と "Estimated Performance" は independent なので、リファクタリングをして解決した方が良いと思います。(変更は大きくなってしまいますが…)

kenkoooo avatar Aug 22 '20 17:08 kenkoooo