Skip to content

Commit e06757c

Browse files
authored
perf(vite): improve data processing in chunk imports (#107)
1 parent cfaa276 commit e06757c

File tree

5 files changed

+54
-34
lines changed

5 files changed

+54
-34
lines changed

packages/vite/src/app/components/data/ChunkDetails.vue

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<script setup lang="ts">
22
import type { Chunk as ChunkInfo } from '@rolldown/debug'
3-
import type { SessionContext } from '~~/shared/types'
3+
import type { RolldownChunkImport, SessionContext } from '~~/shared/types'
4+
import { useRpc } from '#imports'
5+
import { useAsyncState } from '@vueuse/core'
46
import { computed } from 'vue'
57
68
const props = withDefaults(defineProps<{
79
chunk: ChunkInfo
810
session: SessionContext
911
showModules?: boolean
1012
showImports?: boolean
13+
chunks?: ChunkInfo[]
1114
}>(), {
1215
showModules: true,
1316
showImports: true,
@@ -26,6 +29,33 @@ const chunkSize = computed(() => props.chunk.modules.reduce((total, moduleId) =>
2629
const transforms = moduleInfo?.buildMetrics?.transforms
2730
return transforms?.length ? total + transforms[transforms.length - 1]!.transformed_code_size : total
2831
}, 0))
32+
33+
const rpc = useRpc()
34+
const { state, isLoading } = useAsyncState(
35+
async () => {
36+
if (props.chunks)
37+
return
38+
39+
return await rpc.value!['vite:rolldown:get-chunks-graph']?.({
40+
session: props.session.id,
41+
})
42+
},
43+
null,
44+
)
45+
46+
const imports = computed((): RolldownChunkImport[] => {
47+
return props.chunk.imports.map((importChunk) => {
48+
const chunk = (props.chunks || state.value)?.find(c => c.chunk_id === importChunk.chunk_id)
49+
50+
return {
51+
...importChunk,
52+
name: chunk?.name || '[unnamed]',
53+
reason: chunk?.reason || 'common',
54+
imports: chunk?.imports.length || 0,
55+
modules: chunk?.modules.length || 0,
56+
}
57+
})
58+
})
2959
</script>
3060

3161
<template>
@@ -76,13 +106,12 @@ const chunkSize = computed(() => props.chunk.modules.reduce((total, moduleId) =>
76106
<summary op50>
77107
<span>Imports ({{ chunk.imports.length }})</span>
78108
</summary>
79-
<div flex="~ col gap-1" mt2 ws-nowrap>
109+
<VisualLoading v-if="isLoading" />
110+
<div v-else flex="~ col gap-1" mt2 ws-nowrap>
80111
<DisplayChunkImports
81-
v-for="(importChunk, index) in chunk.imports"
82-
:key="index"
83-
:chunk-import="importChunk"
84-
:session="session"
85-
:importer="chunk"
112+
v-for="chunkImport in imports"
113+
:key="chunkImport.chunk_id"
114+
:chunk="chunkImport"
86115
hover="bg-active"
87116
border="~ base rounded" px2 py1 w-full
88117
/>

packages/vite/src/app/components/data/ChunkDetailsLoader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import type { SessionContext } from '../../../shared/types/data'
2+
import type { SessionContext } from '~~/shared/types/data'
33
import { useRpc } from '#imports'
44
import { useAsyncState } from '@vueuse/core'
55

packages/vite/src/app/components/display/ChunkImports.vue

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,26 @@
11
<script lang="ts" setup>
2-
import type { ChunkImport, Chunk as ChunkInfo } from '@rolldown/debug'
3-
import type { SessionContext } from '../../../shared/types/data'
2+
import type { RolldownChunkImport } from '~~/shared/types/data'
43
import { useRoute } from '#app/composables/router'
5-
import { useRpc } from '#imports'
6-
import { useAsyncState } from '@vueuse/core'
74
8-
const props = defineProps<{
9-
chunkImport: ChunkImport
10-
session: SessionContext
11-
importer: ChunkInfo
5+
const { chunk } = defineProps<{
6+
chunk: RolldownChunkImport
127
}>()
138
149
const route = useRoute()
15-
16-
const rpc = useRpc()
17-
const { state: chunk } = useAsyncState(
18-
async () => {
19-
return await rpc.value!['vite:rolldown:get-chunk-info']?.({
20-
session: props.session.id,
21-
id: props.chunkImport.chunk_id,
22-
})
23-
},
24-
null,
25-
)
2610
</script>
2711

2812
<template>
2913
<!-- <VisualLoading /> -->
3014
<NuxtLink v-if="chunk" flex="~ items-center" :to="{ path: route.path, query: { chunk: chunk.chunk_id } }">
3115
<!-- Icon, Name, Reason -->
3216
<div flex="~ gap-2 items-center" :title="`Chunk #${chunk.chunk_id}`">
33-
<div v-if="chunkImport.kind === 'import-statement'" i-ph-file-duotone />
34-
<div v-if="chunkImport.kind === 'dynamic-import'" i-ph-lightning-duotone />
17+
<div v-if="chunk.kind === 'import-statement'" i-ph-file-duotone />
18+
<div v-if="chunk.kind === 'dynamic-import'" i-ph-lightning-duotone />
3519
<div>{{ chunk.name || '[unnamed]' }}</div>
3620
<DisplayBadge :text="chunk.reason" />
3721

3822
<!-- Import Kind -->
39-
<DisplayBadge v-if="chunkImport.kind === 'import-statement'" text="statement" :color="210" />
40-
<DisplayBadge v-if="chunkImport.kind === 'dynamic-import'" text="dynamic" :color="30" />
23+
<DisplayBadge :text="chunk.kind" />
4124
</div>
4225

4326
<div flex-auto />
@@ -46,11 +29,11 @@ const { state: chunk } = useAsyncState(
4629
<span op50 font-mono>#{{ chunk.chunk_id }}</span>
4730
<div flex="~ gap-1 items-center">
4831
<div i-ph-file-arrow-up-duotone />
49-
{{ chunk.imports.length }}
32+
{{ chunk.imports }}
5033
</div>
5134
<div flex="~ gap-1 items-center">
5235
<div i-ph-package-duotone />
53-
{{ chunk.modules.length }}
36+
{{ chunk.modules }}
5437
</div>
5538
</div>
5639
</NuxtLink>

packages/vite/src/app/pages/session/[session]/chunks.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function toggleDisplay(type: ClientSettings['chunkViewType']) {
6868
border="~ base rounded-lg"
6969
p3
7070
:chunk="chunk"
71+
:chunks="chunks!"
7172
:session="session"
7273
/>
7374
</template>

packages/vite/src/shared/types/data.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Asset as AssetInfo, Chunk as ChunkInfo, HookResolveIdCallStart, ModuleImport, PluginItem, SessionMeta } from '@rolldown/debug'
1+
import type { Asset as AssetInfo, ChunkImport, Chunk as ChunkInfo, HookResolveIdCallStart, ModuleImport, PluginItem, SessionMeta } from '@rolldown/debug'
22

33
export type { ModuleImport }
44

@@ -175,3 +175,10 @@ export type RolldownModuleFlowNode
175175
| RolldownModuleTransformInfo
176176
| RolldownChunkInfo
177177
| RolldownAssetInfo
178+
179+
export interface RolldownChunkImport extends ChunkImport {
180+
imports: number
181+
modules: number
182+
name: ChunkInfo['name']
183+
reason: ChunkInfo['reason']
184+
}

0 commit comments

Comments
 (0)