feat: vue nodes LOD system (#5631)

## Summary

Replaced reactive (Vue-based) widget LOD with CSS visibility control.
Performance doesn't dramatically improve, but we avoid the mount/unmount
overhead during zoom/pan operations. This PR implements the visual
component of LOD—complex widgets that need lifecycle management will be
addressed separately.

### Problem & Solution
Problem: we want LOD to improve rendering performance and visual
feedback but discovered using reactivity in the current setup for it
meant mounting/unmounting caused worse lag than the performance it aimed
to fix. Switching to render all the details all the time but using css
visibility proved to be the best solution. However, it doesn't improve
rendering performance by much because the GPU texture size is the
bottleneck (from TransformPane.vue CSS transforms) and not
rasterization.

Solution: Keep all nodes/widgets mounted, use CSS visibility: hidden for
LOD. Trade memory for performance stability during zoom/pan/drag
operations.

### Technical Decision
We chose Performance > Memory:

- CSS transforms create a single GPU texture whose size depends on node
count, not widget complexity
- Mounting/unmounting hundreds of widgets during zoom = noticeable lag
from Vue VDOM diffing (since all components are mounted all the time
because of viewport culling challenge/trade off see
https://github.com/Comfy-Org/ComfyUI_frontend/pull/5510.)
- CSS visibility changes = no reactivity overhead, smooth interactions
- Result: Similar performance, but without interaction stutters

This is the visual layer only. If we want a hook into the LOD state per
node / widget that would be the next follow up system to implement.

### Next Steps (maybe)
- Chunked (split up single Transform Pane transform layer) when
rendering 1000+ nodes (maybe)
- ~~Selective unmounting API for widgets that register as "expensive"~~
- ~~Client bound hydration system~~

## Screenshots (if applicable)

<!-- Add screenshots or video recording to help explain your changes -->

<img width="1355" height="960" alt="image"
src="https://github.com/user-attachments/assets/41474d1b-9dbe-4240-a8cf-f4c9ff51d8e0"
/>
<img width="1354" height="963" alt="image"
src="https://github.com/user-attachments/assets/9f55edaa-5858-41b9-b6a8-c2d37e1649bd"
/>


┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-5631-feat-vue-nodes-LOD-system-2726d73d365081c6a6c4e14aa634f19c)
by [Unito](https://www.unito.io)

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Simula_r
2025-09-22 20:05:13 -07:00
committed by GitHub
parent b4976c1ddc
commit cec1de0147
23 changed files with 381 additions and 874 deletions

View File

@@ -57,17 +57,6 @@ vi.mock('@/renderer/extensions/vueNodes/layout/useNodeLayout', () => ({
})
}))
vi.mock('@/renderer/extensions/vueNodes/lod/useLOD', () => ({
useLOD: () => ({
lodLevel: { value: 0 },
shouldRenderWidgets: { value: true },
shouldRenderSlots: { value: true },
shouldRenderContent: { value: false },
lodCssClass: { value: '' }
}),
LODLevel: { MINIMAL: 0 }
}))
vi.mock(
'@/renderer/extensions/vueNodes/execution/useNodeExecutionState',
() => ({

View File

@@ -1,270 +1,69 @@
import { describe, expect, it } from 'vitest'
import { ref } from 'vue'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { nextTick, reactive } from 'vue'
import {
LODLevel,
LOD_THRESHOLDS,
supportsFeatureAtZoom,
useLOD
} from '@/renderer/extensions/vueNodes/lod/useLOD'
import { useLOD } from '@/renderer/extensions/vueNodes/lod/useLOD'
const mockSettingStore = reactive({
get: vi.fn(() => 8)
})
vi.mock('@/platform/settings/settingStore', () => ({
useSettingStore: () => mockSettingStore
}))
describe('useLOD', () => {
describe('LOD level detection', () => {
it('should return MINIMAL for zoom <= 0.4', () => {
const zoomRef = ref(0.4)
const { lodLevel } = useLOD(zoomRef)
expect(lodLevel.value).toBe(LODLevel.MINIMAL)
beforeEach(() => {
vi.restoreAllMocks()
vi.unstubAllGlobals()
zoomRef.value = 0.2
expect(lodLevel.value).toBe(LODLevel.MINIMAL)
zoomRef.value = 0.1
expect(lodLevel.value).toBe(LODLevel.MINIMAL)
})
it('should return REDUCED for 0.4 < zoom <= 0.8', () => {
const zoomRef = ref(0.5)
const { lodLevel } = useLOD(zoomRef)
expect(lodLevel.value).toBe(LODLevel.REDUCED)
zoomRef.value = 0.6
expect(lodLevel.value).toBe(LODLevel.REDUCED)
zoomRef.value = 0.8
expect(lodLevel.value).toBe(LODLevel.REDUCED)
})
it('should return FULL for zoom > 0.8', () => {
const zoomRef = ref(0.9)
const { lodLevel } = useLOD(zoomRef)
expect(lodLevel.value).toBe(LODLevel.FULL)
zoomRef.value = 1.0
expect(lodLevel.value).toBe(LODLevel.FULL)
zoomRef.value = 2.5
expect(lodLevel.value).toBe(LODLevel.FULL)
})
it('should be reactive to zoom changes', () => {
const zoomRef = ref(0.2)
const { lodLevel } = useLOD(zoomRef)
expect(lodLevel.value).toBe(LODLevel.MINIMAL)
zoomRef.value = 0.6
expect(lodLevel.value).toBe(LODLevel.REDUCED)
zoomRef.value = 1.0
expect(lodLevel.value).toBe(LODLevel.FULL)
})
mockSettingStore.get.mockReturnValue(8)
})
describe('rendering decisions', () => {
it('should disable all rendering for MINIMAL LOD', () => {
const zoomRef = ref(0.2)
const {
shouldRenderWidgets,
shouldRenderSlots,
shouldRenderContent,
shouldRenderSlotLabels,
shouldRenderWidgetLabels
} = useLOD(zoomRef)
it('should calculate isLOD value based on zoom threshold correctly', async () => {
vi.stubGlobal('devicePixelRatio', 1)
expect(shouldRenderWidgets.value).toBe(false)
expect(shouldRenderSlots.value).toBe(false)
expect(shouldRenderContent.value).toBe(false)
expect(shouldRenderSlotLabels.value).toBe(false)
expect(shouldRenderWidgetLabels.value).toBe(false)
})
const camera = reactive({ z: 1 })
const { isLOD } = useLOD(camera)
it('should enable widgets/slots but disable labels for REDUCED LOD', () => {
const zoomRef = ref(0.6)
const {
shouldRenderWidgets,
shouldRenderSlots,
shouldRenderContent,
shouldRenderSlotLabels,
shouldRenderWidgetLabels
} = useLOD(zoomRef)
await nextTick()
expect(isLOD.value).toBe(false)
expect(shouldRenderWidgets.value).toBe(true)
expect(shouldRenderSlots.value).toBe(true)
expect(shouldRenderContent.value).toBe(false)
expect(shouldRenderSlotLabels.value).toBe(false)
expect(shouldRenderWidgetLabels.value).toBe(false)
})
camera.z = 0.55
await nextTick()
expect(isLOD.value).toBe(true)
it('should enable all rendering for FULL LOD', () => {
const zoomRef = ref(1.0)
const {
shouldRenderWidgets,
shouldRenderSlots,
shouldRenderContent,
shouldRenderSlotLabels,
shouldRenderWidgetLabels
} = useLOD(zoomRef)
expect(shouldRenderWidgets.value).toBe(true)
expect(shouldRenderSlots.value).toBe(true)
expect(shouldRenderContent.value).toBe(true)
expect(shouldRenderSlotLabels.value).toBe(true)
expect(shouldRenderWidgetLabels.value).toBe(true)
})
camera.z = 0.87
await nextTick()
expect(isLOD.value).toBe(false)
})
describe('CSS classes', () => {
it('should return correct CSS class for each LOD level', () => {
const zoomRef = ref(0.2)
const { lodCssClass } = useLOD(zoomRef)
it('should handle a different devicePixelRatio value', async () => {
vi.stubGlobal('devicePixelRatio', 3) //Threshold with 8px minFontsize = 0.19
expect(lodCssClass.value).toBe('lg-node--lod-minimal')
const camera = reactive({ z: 1 })
const { isLOD } = useLOD(camera)
zoomRef.value = 0.6
expect(lodCssClass.value).toBe('lg-node--lod-reduced')
await nextTick()
expect(isLOD.value).toBe(false)
zoomRef.value = 1.0
expect(lodCssClass.value).toBe('lg-node--lod-full')
})
camera.z = 0.18
await nextTick()
expect(isLOD.value).toBe(true)
})
describe('essential widgets filtering', () => {
it('should return all widgets for FULL LOD', () => {
const zoomRef = ref(1.0)
const { getEssentialWidgets } = useLOD(zoomRef)
it('should respond to different minFontSize settings', async () => {
vi.stubGlobal('devicePixelRatio', 1)
const widgets = [
{ type: 'combo' },
{ type: 'text' },
{ type: 'button' },
{ type: 'slider' }
]
mockSettingStore.get.mockReturnValue(16) //Now threshold is 1.14
expect(getEssentialWidgets(widgets)).toEqual(widgets)
})
const camera = reactive({ z: 1 })
const { isLOD } = useLOD(camera)
it('should return empty array for MINIMAL LOD', () => {
const zoomRef = ref(0.2)
const { getEssentialWidgets } = useLOD(zoomRef)
await nextTick()
expect(isLOD.value).toBe(true)
const widgets = [{ type: 'combo' }, { type: 'text' }, { type: 'button' }]
expect(getEssentialWidgets(widgets)).toEqual([])
})
it('should filter to essential types for REDUCED LOD', () => {
const zoomRef = ref(0.6)
const { getEssentialWidgets } = useLOD(zoomRef)
const widgets = [
{ type: 'combo' },
{ type: 'text' },
{ type: 'button' },
{ type: 'slider' },
{ type: 'toggle' },
{ type: 'number' }
]
const essential = getEssentialWidgets(widgets)
expect(essential).toHaveLength(4)
expect(essential.map((w: any) => w.type)).toEqual([
'combo',
'slider',
'toggle',
'number'
])
})
it('should handle case-insensitive widget types', () => {
const zoomRef = ref(0.6)
const { getEssentialWidgets } = useLOD(zoomRef)
const widgets = [
{ type: 'COMBO' },
{ type: 'Select' },
{ type: 'TOGGLE' }
]
const essential = getEssentialWidgets(widgets)
expect(essential).toHaveLength(3)
})
it('should handle widgets with undefined or missing type', () => {
const zoomRef = ref(0.6)
const { getEssentialWidgets } = useLOD(zoomRef)
const widgets = [
{ type: 'combo' },
{ type: undefined },
{},
{ type: 'slider' }
]
const essential = getEssentialWidgets(widgets)
expect(essential).toHaveLength(2)
expect(essential.map((w: any) => w.type)).toEqual(['combo', 'slider'])
})
})
describe('performance metrics', () => {
it('should provide debug metrics', () => {
const zoomRef = ref(0.6)
const { lodMetrics } = useLOD(zoomRef)
expect(lodMetrics.value).toEqual({
level: LODLevel.REDUCED,
zoom: 0.6,
widgetCount: 'full',
slotCount: 'full'
})
})
it('should update metrics when zoom changes', () => {
const zoomRef = ref(0.2)
const { lodMetrics } = useLOD(zoomRef)
expect(lodMetrics.value.level).toBe(LODLevel.MINIMAL)
expect(lodMetrics.value.widgetCount).toBe('none')
expect(lodMetrics.value.slotCount).toBe('none')
zoomRef.value = 1.0
expect(lodMetrics.value.level).toBe(LODLevel.FULL)
expect(lodMetrics.value.widgetCount).toBe('full')
expect(lodMetrics.value.slotCount).toBe('full')
})
})
})
describe('LOD_THRESHOLDS', () => {
it('should export correct threshold values', () => {
expect(LOD_THRESHOLDS.FULL_THRESHOLD).toBe(0.8)
expect(LOD_THRESHOLDS.REDUCED_THRESHOLD).toBe(0.4)
expect(LOD_THRESHOLDS.MINIMAL_THRESHOLD).toBe(0.0)
})
})
describe('supportsFeatureAtZoom', () => {
it('should return correct feature support for different zoom levels', () => {
expect(supportsFeatureAtZoom(1.0, 'renderWidgets')).toBe(true)
expect(supportsFeatureAtZoom(1.0, 'renderSlots')).toBe(true)
expect(supportsFeatureAtZoom(1.0, 'renderContent')).toBe(true)
expect(supportsFeatureAtZoom(0.6, 'renderWidgets')).toBe(true)
expect(supportsFeatureAtZoom(0.6, 'renderSlots')).toBe(true)
expect(supportsFeatureAtZoom(0.6, 'renderContent')).toBe(false)
expect(supportsFeatureAtZoom(0.2, 'renderWidgets')).toBe(false)
expect(supportsFeatureAtZoom(0.2, 'renderSlots')).toBe(false)
expect(supportsFeatureAtZoom(0.2, 'renderContent')).toBe(false)
})
it('should handle threshold boundary values correctly', () => {
expect(supportsFeatureAtZoom(0.8, 'renderWidgets')).toBe(true)
expect(supportsFeatureAtZoom(0.8, 'renderContent')).toBe(false)
expect(supportsFeatureAtZoom(0.81, 'renderContent')).toBe(true)
expect(supportsFeatureAtZoom(0.4, 'renderWidgets')).toBe(false)
expect(supportsFeatureAtZoom(0.41, 'renderWidgets')).toBe(true)
camera.z = 1.15
await nextTick()
expect(isLOD.value).toBe(false)
})
})