From 03a1cd62251cf62f1622b897b0f1a06aece5777b Mon Sep 17 00:00:00 2001 From: Kevin Zheng Date: Wed, 15 Nov 2023 16:59:00 +1100 Subject: [PATCH] Performance improvements for search trace parsing --- client/src/components/app-bar/Playback.tsx | 22 ++-- .../src/components/inspector/PropertyList.tsx | 4 +- .../components/renderer/parser/applyScope.ts | 14 +- .../renderer/parser/mapProperties.ts | 17 +-- .../components/renderer/parser/normalize.ts | 4 +- .../src/components/renderer/parser/parse.ts | 10 +- .../renderer/parser/parseProperty.ts | 4 +- .../components/renderer/parser/parseString.ts | 17 +-- .../components/renderer/parser/parseToken.ts | 4 +- .../components/renderer/parser/parseTrace.ts | 7 +- .../renderer/parser/parseTrace.worker.ts | 123 +++++------------- .../renderer/parser/parseTraceSlave.worker.ts | 104 +++++++++++++++ client/src/pages/SettingsPage.tsx | 8 +- client/src/slices/settings.ts | 10 +- .../src/d2-renderer/D2RendererOptions.ts | 4 +- 15 files changed, 205 insertions(+), 147 deletions(-) create mode 100644 client/src/components/renderer/parser/parseTraceSlave.worker.ts diff --git a/client/src/components/app-bar/Playback.tsx b/client/src/components/app-bar/Playback.tsx index 7d71b5c6..594e37db 100644 --- a/client/src/components/app-bar/Playback.tsx +++ b/client/src/components/app-bar/Playback.tsx @@ -11,9 +11,8 @@ import { Label } from "components/generic/Label"; import { useSnackbar } from "components/generic/Snackbar"; import { useBreakpoints } from "hooks/useBreakpoints"; import { usePlaybackState } from "hooks/usePlaybackState"; -import { range, trimEnd } from "lodash"; +import { noop, range, trimEnd } from "lodash"; import { ReactNode, useCallback, useEffect } from "react"; -import { useRaf } from "react-use"; import { UploadedTrace } from "slices/UIState"; import { Layer } from "slices/layers"; import { useSettings } from "slices/settings"; @@ -38,7 +37,6 @@ export function PlaybackService({ children, value, }: EditorSetterProps>) { - useRaf(); const { step, tick, end, playing, pause } = usePlaybackState(value?.key); const notify = useSnackbar(); @@ -54,8 +52,10 @@ export function PlaybackService({ useEffect(() => { if (playing) { - return step < end - ? cancellable( + let cancel = noop; + const r = setInterval(() => { + if (step < end) { + cancel = cancellable( async () => { for (const i of range(playbackRate)) { const r = shouldBreak(step + i); @@ -74,8 +74,15 @@ export function PlaybackService({ pause(); } } - ) - : pause(); + ); + } else { + pause(); + } + }, 1000 / 60); + return () => { + cancel(); + clearInterval(r); + }; } }, [ renderLabel, @@ -109,7 +116,6 @@ export function Playback({ stepForward, stop, } = usePlaybackState(layer?.key); - useRaf(); return ( <>