-
Notifications
You must be signed in to change notification settings - Fork 8
fix: virtualize tree children to fix UI lag with many nodes (Fixes #47) #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bf4f94d
dd145ff
350b3d9
aadda7a
e3e172c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,4 @@ | |
| "ignoreDeps": [ | ||
| "@types/vscode" | ||
| ] | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,14 +133,16 @@ export function showTree(startsWith: string, sourceFileName: string, position: n | |
| return nodes | ||
| } | ||
|
|
||
| export function getChildrenById(id: number) { | ||
| export function getChildrenById(id: number, limit: number = 50, offset: number = 0) { | ||
| const nodes = treeIdNodes.get(id)?.children ?? [] | ||
| const ret: typeof nodes = [] | ||
| nodes.forEach((node) => { | ||
| const total = nodes.length | ||
| const paginatedNodes = nodes.slice(offset, offset + limit) | ||
| const ret: typeof paginatedNodes = [] | ||
| paginatedNodes.forEach((node) => { | ||
|
Comment on lines
+136
to
+141
|
||
| treeIdNodes.set(node.id, node) | ||
| ret.push({ ...node, children: [], types: [] }) | ||
| }) | ||
| return ret | ||
| return { children: ret, total } | ||
| } | ||
|
|
||
| export function getTypesById(id: number) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,17 +1,29 @@ | ||||||||||||||
| <script setup lang="ts"> | ||||||||||||||
| import type { Tree } from '../../src/traceTree' | ||||||||||||||
| import { childrenById, typesById } from '~/src/appState' | ||||||||||||||
| import { childrenById, childrenTotalById, typesById } from '~/src/appState' | ||||||||||||||
|
|
||||||||||||||
| const props = defineProps<{ tree: Tree, depth: number }>() | ||||||||||||||
|
|
||||||||||||||
| const sendMessage = useNuxtApp().$sendMessage | ||||||||||||||
|
|
||||||||||||||
| const children = computed(() => childrenById.get(props.tree.id) ?? []) | ||||||||||||||
| const totalChildren = computed(() => childrenTotalById.get(props.tree.id)) | ||||||||||||||
| const types = computed(() => typesById.get(props.tree.id) ?? []) | ||||||||||||||
|
|
||||||||||||||
| // Pagination state | ||||||||||||||
| const offset = ref(0) | ||||||||||||||
| const limit = 50 | ||||||||||||||
|
|
||||||||||||||
| function fetchChildren() { | ||||||||||||||
| if (children.value.length === 0) | ||||||||||||||
| sendMessage('childrenById', { id: props.tree.id }) | ||||||||||||||
| sendMessage('childrenById', { id: props.tree.id, limit, offset: offset.value }) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function loadMoreChildren() { | ||||||||||||||
| // Load next batch of children | ||||||||||||||
| const newOffset = offset.value + limit | ||||||||||||||
| offset.value = newOffset | ||||||||||||||
| sendMessage('childrenById', { id: props.tree.id, limit, offset: newOffset }) | ||||||||||||||
|
Comment on lines
+13
to
+26
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function fetchTypes() { | ||||||||||||||
|
|
@@ -78,6 +90,11 @@ const insetClass = `border-e min-w-2 border-[var(--vscode-tree-inactiveIndentGui | |||||||||||||
| <template v-for="(node, idx) of children" :key="idx"> | ||||||||||||||
| <TreeNode :depth="depth + 1" :tree="node" /> | ||||||||||||||
| </template> | ||||||||||||||
| <div v-if="totalChildren !== undefined && children.length + offset < totalChildren" class="flex justify-center py-2 pl-8"> | ||||||||||||||
| <button class="px-4 py-1 bg-[var(--vscode-button-background)] text-[var(--vscode-button-foreground)] rounded hover:opacity-80 transition-opacity text-sm" @click="loadMoreChildren"> | ||||||||||||||
| Load More ({{ children.length + offset }}/{{ totalChildren }}) | ||||||||||||||
|
Comment on lines
+93
to
+95
|
||||||||||||||
| <div v-if="totalChildren !== undefined && children.length + offset < totalChildren" class="flex justify-center py-2 pl-8"> | |
| <button class="px-4 py-1 bg-[var(--vscode-button-background)] text-[var(--vscode-button-foreground)] rounded hover:opacity-80 transition-opacity text-sm" @click="loadMoreChildren"> | |
| Load More ({{ children.length + offset }}/{{ totalChildren }}) | |
| <div v-if="totalChildren !== undefined && children.length < totalChildren" class="flex justify-center py-2 pl-8"> | |
| <button class="px-4 py-1 bg-[var(--vscode-button-background)] text-[var(--vscode-button-foreground)] rounded hover:opacity-80 transition-opacity text-sm" @click="loadMoreChildren"> | |
| Load More ({{ children.length }}/{{ totalChildren }}) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import type { Tree } from '../../src/traceTree' | |
| import * as Messages from '../../shared/src/messages' | ||
|
|
||
| export const childrenById = shallowReactive(new Map<number, Tree[]>()) | ||
| export const childrenTotalById = shallowReactive(new Map<number, number>()) | ||
| export const typesById = shallowReactive(new Map<number, TypeLine[]>()) | ||
|
Comment on lines
5
to
7
|
||
| export const nodes = ref([] as Tree[]) | ||
| export const sortBy = ref('Timestamp' as keyof typeof sortValue) | ||
|
|
@@ -40,6 +41,8 @@ function handleMessage(e: MessageEvent<unknown>) { | |
| const id = parsed.data.id | ||
| const children = childrenById.get(id) ?? [] | ||
| childrenById.set(id, [...children, ...parsed.data.children]) | ||
| if (parsed.data.total !== undefined) | ||
| childrenTotalById.set(id, parsed.data.total) | ||
| break | ||
| } | ||
| case 'typesById': { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message schema accepts any numeric
limit/offset. To avoid abuse and accidental UI freezes, constrain these (e.g., non-negative offset, reasonable max limit) at the schema level (zod refinements) and/or in the message handler before callinggetChildrenById.