Skip to content

Commit e4d45c6

Browse files
sean-zlaitechniq
andauthored
Improve PercentileLineChart perf (and thus Summary page) by over 20x (#469)
## Summary By extracting `series` from the markup (which made it reactive) and intentionally NOT using `$derived`, rendering performance of `PercentileLineChart` improved by over 20x (`>1100ms` down to `<50ms`). This makes navigating to the Summary tab MUCH better (before we would sometimes hit the browser "Are you sure you want to wait" prompts). `$state.opaque()` runes was being [considered](sveltejs/svelte#14639) that could have helped here, but it was decided to not be the right abstraction. (I'm waiting on a solution to fix LayerChart's force simulations that have a perf regression in Svelte 5 due to granular reactivity / proxy creation) ## Before https://github.com/user-attachments/assets/9e93f4eb-5247-4bff-a56d-413564e50022 ## After https://github.com/user-attachments/assets/8dbe075d-0479-4d5e-a3f8-45fb1d350402 ## Checklist - [ ] Added Unit Tests - [ ] Covered by existing CI - [ ] Integration tested - [ ] Documentation update <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Optimized the chart component's data handling to improve performance and overall clarity. - Adjusted the internal structure by moving data definitions outside inline usage and refining type specifications for better consistency. <!-- end of auto-generated comment: release notes by coderabbit.ai --> <!-- av pr metadata This information is embedded by the av CLI when creating PRs to track the status of stacks when using Aviator. Please do not delete or edit this section of the PR. ``` {"parent":"main","parentHead":"","trunk":"main"} ``` --> --------- Co-authored-by: Sean Lynch <[email protected]>
1 parent 13ee2d1 commit e4d45c6

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

frontend/src/lib/components/charts/PercentileLineChart.svelte

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<script lang="ts">
2-
import type { ComponentProps } from 'svelte';
2+
import { type ComponentProps } from 'svelte';
33
import { LineChart } from 'layerchart';
44
import merge from 'lodash/merge';
55
66
import { lineChartProps } from './common';
77
import type { ITileSummarySeriesArgs } from '$src/lib/types/codegen';
88
import { zip } from 'd3';
9-
import { Int64 } from '@creditkarma/thrift-server-core';
109
import { NULL_VALUE } from '$src/lib/constants/common';
1110
1211
type LineChartProps = ComponentProps<typeof LineChart>;
@@ -18,12 +17,9 @@
1817
} & Omit<LineChartProps, 'data'>;
1918
2019
let { data, onbrushend, ...restProps }: Props = $props();
21-
</script>
2220
23-
<LineChart
24-
x="date"
25-
y="value"
26-
series={[
21+
// Using `$derived()` or defining inline causes performance issue (likely due to creating proxies for deep reactivity).
22+
const series = [
2723
{ label: 'p95', color: '#2976E6', index: 2 },
2824
{ label: 'p50', color: '#3DDC91', index: 1 },
2925
{ label: 'p5', color: '#E5B72D', index: 0 }
@@ -33,18 +29,24 @@
3329
3430
return {
3531
key: c.label,
36-
data: zip<Int64 | number>(
32+
data: zip(
3733
timestamps.map((ts) => Number(ts)),
3834
values
39-
).map(([ts, value]) => {
35+
).map(([ts, value]: number[]) => {
4036
return {
4137
date: new Date(ts as number),
4238
value: value === NULL_VALUE ? null : value
4339
};
4440
}),
4541
color: c.color
4642
};
47-
})}
43+
});
44+
</script>
45+
46+
<LineChart
47+
x="date"
48+
y="value"
49+
{series}
4850
padding={{ top: 4, left: 36, bottom: 20 }}
4951
brush={{ onbrushend }}
5052
{...merge(

0 commit comments

Comments
 (0)