Skip to content

Commit

Permalink
perf: memoize the proxy col items (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
oomeow committed May 18, 2024
1 parent db5d14e commit 43f0b93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/proxy/proxy-groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const ProxyGroups = (props: Props) => {
return (
<Virtuoso
ref={virtuosoRef}
style={{ height: "calc(100% - 12px)" }}
style={{ height: "calc(100% - 16px)" }}
totalCount={renderList.length}
increaseViewportBy={256}
itemContent={(index) => (
Expand Down
25 changes: 14 additions & 11 deletions src/components/proxy/proxy-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { IRenderItem } from "./use-render-list";
import { useVerge } from "@/hooks/use-verge";
import { useRecoilState } from "recoil";
import { atomThemeMode } from "@/services/states";
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { convertFileSrc } from "@tauri-apps/api/tauri";
import { downloadIconCache } from "@/services/cmds";

Expand Down Expand Up @@ -171,6 +171,18 @@ export const ProxyRender = (props: RenderProps) => {
}

if (type === 4 && !group.hidden) {
const proxyColItemsMemo = useMemo(() => {
return proxyCol?.map((proxy) => (
<ProxyItemMini
key={item.key + proxy.name}
group={group}
proxy={proxy!}
selected={group.now === proxy.name}
showType={headState?.showType}
onClick={() => onChangeProxy(group, proxy!)}
/>
));
}, [proxyCol, group, headState]);
return (
<Box
sx={{
Expand All @@ -183,16 +195,7 @@ export const ProxyRender = (props: RenderProps) => {
gridTemplateColumns: `repeat(${item.col! || 2}, 1fr)`,
}}
>
{proxyCol?.map((proxy) => (
<ProxyItemMini
key={item.key + proxy.name}
group={group}
proxy={proxy!}
selected={group.now === proxy.name}
showType={headState?.showType}
onClick={() => onChangeProxy(group, proxy!)}
/>
))}
{proxyColItemsMemo}
</Box>
);
}
Expand Down

0 comments on commit 43f0b93

Please sign in to comment.