Skip to content

Commit ebd67d1

Browse files
Copilothortison
andcommitted
docs(kanvas): expand performance documentation with detailed analysis and optimizations
Co-authored-by: hortison <[email protected]>
1 parent 8014d77 commit ebd67d1

File tree

3 files changed

+617
-492
lines changed

3 files changed

+617
-492
lines changed

content/en/kanvas/advanced/performance/index.md

Lines changed: 384 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,387 @@ To optimize performance, consider the following:
9898
2. Prioritize using smaller file sizes whenever possible. Use the `webp` image format over `png`, `jpg`, or `gif` as it generally provides significantly better compression, resulting in faster design save times without sacrificing much image quality.
9999
3. Remove any unnecessary images from your design.
100100
4. Use image compression tools to reduce the size of your images before adding them to your design.
101+
102+
## Compound Node Rendering Performance
103+
104+
When working with compound nodes (parent nodes containing multiple child nodes), you may encounter performance challenges as the number of children increases. Understanding these issues and the optimizations available can help you create more responsive designs.
105+
106+
### Root Cause Analysis
107+
108+
The rendering performance of compound nodes with many children can be significantly impacted by several factors:
109+
110+
- **Badge Rendering Plugin Overhead**: The `@layer5/cytoscape-node-html-label` plugin, while powerful for rendering badges and labels, can become a performance bottleneck for compound nodes with many children.
111+
- **Overly Broad Selectors**: The badge selector `node[?label]` matches virtually every node in the graph, causing unnecessary re-renders even for nodes that haven't changed.
112+
- **Missing Viewport Culling**: Badges are rendered for all nodes in the design, even those currently off-screen and not visible to the user, wasting computational resources.
113+
- **Re-render Multiplication**: With 100 child nodes in a compound parent, approximately 303 badge re-renders occur per update cycle.
114+
- **Drag Operation Overhead**: During interactive operations like dragging, the system can generate 18,000-36,000 function calls per second, leading to UI lag and poor user experience.
115+
116+
{{< alert type="warning" title="Performance Impact" >}}
117+
Large compound nodes (100+ children) can experience significant lag during drag operations and viewport changes without proper optimizations.
118+
{{< /alert >}}
119+
120+
### Performance Metrics
121+
122+
The following table illustrates the dramatic performance improvements achieved through optimization:
123+
124+
| Scenario | Before Optimization | After Optimization | Improvement |
125+
|----------|---------------------|-------------------|-------------|
126+
| Badge re-renders per update (100 children) | 303 | ~30 | 90% reduction |
127+
| Function calls/sec during drag | 18,000-36,000 | 500-3,000 | 90-95% reduction |
128+
| Perceived responsiveness | Laggy, choppy | Smooth, responsive | Significantly improved |
129+
130+
### Optimizations Implemented
131+
132+
Kanvas incorporates several key optimizations to address compound node rendering performance:
133+
134+
#### 1. Viewport Culling (50-80% reduction)
135+
136+
Only badges for nodes currently visible in the viewport are rendered. Nodes outside the visible area are skipped, reducing unnecessary computation.
137+
138+
{{< alert type="success" title="Automatic Optimization" >}}
139+
Viewport culling is automatically enabled in Kanvas. No configuration is required to benefit from this optimization.
140+
{{< /alert >}}
141+
142+
#### 2. Increased Memoization TTL (70% reduction)
143+
144+
Badge rendering is intelligently cached to avoid redundant computations:
145+
146+
- **Error Badges**: Cache duration increased from 300ms to 1000ms
147+
- **Compound Badges**: Cache duration increased from 200ms to 1000ms
148+
149+
This means that if a node's state hasn't changed, its badge rendering is reused from cache rather than recomputed.
150+
151+
#### 3. Combined Impact (90-95% reduction)
152+
153+
When viewport culling and increased memoization work together, the overall reduction in badge re-renders reaches 90-95%, resulting in a dramatically more responsive user interface even with complex compound nodes.
154+
155+
{{< alert type="note" title="Technical Reference" >}}
156+
These optimizations were implemented in PR #3917 and address issues documented in #3916 from the layer5labs/meshery-extensions repository.
157+
{{< /alert >}}
158+
159+
## Cytoscape Plugin Performance Considerations
160+
161+
Kanvas leverages multiple Cytoscape.js plugins to provide rich interactive features. Understanding the performance characteristics of these plugins can help you anticipate and mitigate potential performance issues.
162+
163+
### Plugin-Specific Performance Characteristics
164+
165+
#### Compound Drag-and-Drop Plugin
166+
167+
The compound drag-and-drop functionality may experience performance degradation with large graphs. This is a known limitation documented in the plugin's own README. If you're working with designs containing hundreds of nodes, consider:
168+
169+
- Breaking your design into multiple smaller designs
170+
- Using the Layers panel to hide unnecessary components during editing
171+
- Limiting the number of compound nodes with large child counts
172+
173+
#### Event Cascade Issues
174+
175+
Multiple plugins listening to the same Cytoscape events can create a multiplication effect that compounds performance overhead:
176+
177+
- **Grid Guide Plugin**: Listens for drag events to display alignment guides
178+
- **Automove Plugin**: Monitors node movements to maintain relationships
179+
- **Popper Plugin**: Tracks node positions for tooltip positioning
180+
181+
When all these plugins respond to a single drag event, the computational cost multiplies, potentially causing lag during interactive operations.
182+
183+
{{< alert type="info" title="Performance Tip" >}}
184+
The impact of event cascades is most noticeable during continuous operations like dragging. The render throttling optimizations described later in this document help mitigate this issue.
185+
{{< /alert >}}
186+
187+
#### HTML Plugin Overhead
188+
189+
Earlier versions of Kanvas used DOM-based HTML rendering for interactive elements. Migration to a 2D canvas renderer has provided significant performance improvements for:
190+
191+
- **Resize Handles**: Canvas-based handles render faster and respond more smoothly
192+
- **Overlays**: Canvas overlays avoid DOM manipulation overhead
193+
- **Interactive Controls**: Canvas-based controls reduce browser reflow and repaint operations
194+
195+
#### Bubblesets Optimization
196+
197+
For designs with complex relationship visualizations, the Bubblesets algorithm has been optimized to provide better performance through improved algorithms that reduce computational complexity.
198+
199+
{{< alert type="note" title="Technical Reference" >}}
200+
These optimizations were implemented across multiple PRs: #3885, #3887, and #3500 from the layer5labs/meshery-extensions repository.
201+
{{< /alert >}}
202+
203+
## State Management and Rendering Optimizations
204+
205+
Efficient state management is critical for maintaining good performance as your designs grow in complexity. Kanvas employs several sophisticated techniques to optimize state updates and rendering.
206+
207+
### Fine-Grained Reactivity
208+
209+
Instead of expensive JSON snapshot computations that process the entire design state, Kanvas uses fine-grained state updates that only affect the specific parts of the design that have changed.
210+
211+
**Benefits:**
212+
- Reduced CPU usage during state updates
213+
- Faster response times for user interactions
214+
- Lower memory consumption
215+
- More predictable performance characteristics
216+
217+
{{< alert type="success" title="Automatic Optimization" >}}
218+
Fine-grained reactivity is built into Kanvas's state management system and requires no configuration.
219+
{{< /alert >}}
220+
221+
### Render Throttling
222+
223+
To prevent UI thrashing during continuous operations, Kanvas implements render throttling that locks down re-renders to a maximum of 10 per second during operations like:
224+
225+
- Dragging nodes or groups of nodes
226+
- Resizing components
227+
- Panning and zooming the viewport
228+
- Bulk operations affecting multiple components
229+
230+
This ensures that the UI remains responsive even during intensive operations, preventing the browser from becoming overwhelmed with render requests.
231+
232+
**Target Performance:**
233+
- Maximum re-renders: 10 per second
234+
- Frame time budget: ~100ms per render
235+
- Typical user-perceived lag: Minimal to none
236+
237+
### Selector Optimization
238+
239+
Cytoscape selectors used for sharedState snapshots have been optimized to reduce computational overhead:
240+
241+
- Use specific selectors instead of broad queries when possible
242+
- Cache selector results when appropriate
243+
- Minimize the number of selector evaluations per frame
244+
- Defer non-critical selector operations to idle time
245+
246+
### Evaluation Deferral
247+
248+
Kanvas intelligently skips unnecessary feasibility evaluations for events that don't require validation:
249+
250+
- **Tap Events**: No feasibility check needed for simple selections
251+
- **Double-Click Events**: Validation deferred until action is confirmed
252+
- **Hover Events**: No evaluation unless tooltip or preview is needed
253+
254+
This reduces computational overhead for common user interactions that don't modify the design.
255+
256+
{{< alert type="note" title="Technical Reference" >}}
257+
State management optimizations were implemented in PRs #3448, #3595, #3121, and #3114 from the layer5labs/meshery-extensions repository.
258+
{{< /alert >}}
259+
260+
## Zoom and Viewport Performance
261+
262+
The zoom level and viewport position significantly impact rendering performance. Kanvas implements several optimizations to ensure smooth performance across all zoom levels.
263+
264+
### Minimum Zoom Viewport
265+
266+
Maintaining a consistent minimum zoom level ensures that detailed rendering works properly across all interactive elements:
267+
268+
- **Layers**: All layers render consistently at minimum zoom
269+
- **Badges**: Error, warning, and info badges remain visible and properly sized
270+
- **Textboxes**: Text remains readable without excessive scaling
271+
- **Interactions**: Interactive handles and controls maintain proper hit targets
272+
- **Device Compatibility**: Consistent experience across desktop, tablet, and mobile devices
273+
274+
{{< alert type="warning" title="Zoom Limits" >}}
275+
Kanvas enforces minimum and maximum zoom limits to ensure optimal rendering performance and usability. Attempting to zoom beyond these limits will have no effect.
276+
{{< /alert >}}
277+
278+
### Progressive Detail Rendering
279+
280+
Kanvas implements view filtering based on zoom level to show more or less detail depending on the current viewport:
281+
282+
- **Zoomed Out (Low Detail)**: Show component shapes and primary labels only
283+
- **Medium Zoom**: Add relationship lines and secondary labels
284+
- **Zoomed In (High Detail)**: Show all badges, annotations, and detailed metadata
285+
286+
This approach ensures that rendering resources are focused on visible, meaningful details at each zoom level.
287+
288+
**Performance Benefits:**
289+
- Reduced rendering overhead at low zoom levels
290+
- Faster panning and zooming operations
291+
- Smoother performance with large designs
292+
- Better user experience with progressive disclosure of information
293+
294+
### Zoom Rendering Consistency
295+
296+
Fixes have been implemented to ensure consistent rendering behavior at all zoom levels:
297+
298+
- Badges maintain proper sizing relative to nodes
299+
- Relationship lines scale appropriately
300+
- Interactive handles remain accessible
301+
- Text remains readable without pixelation
302+
303+
{{< alert type="note" title="Technical Reference" >}}
304+
Zoom and viewport optimizations were implemented in PRs #3528, #3711, and #2292 from the layer5labs/meshery-extensions repository.
305+
{{< /alert >}}
306+
307+
## Performance Testing Guidelines
308+
309+
Regular performance testing helps ensure that your designs remain responsive as they grow in complexity. Use these guidelines to validate performance characteristics.
310+
311+
### Test Scenarios
312+
313+
Validate performance across a range of design complexities:
314+
315+
1. **Baseline Scenario**: 1 parent + 10 children
316+
- Expected behavior: Smooth, lag-free interactions
317+
- Use case: Small component groups, basic hierarchies
318+
319+
2. **Medium Complexity**: 1 parent + 50 children
320+
- Expected behavior: Responsive with minor delays acceptable
321+
- Use case: Moderate-sized microservice architectures, namespace groups
322+
323+
3. **Large/Complex**: 1 parent + 100 children
324+
- Expected behavior: Acceptable performance with optimizations
325+
- Use case: Large namespaces, complex service meshes, cluster visualizations
326+
327+
4. **Stress Test**: 3 levels of nesting
328+
- Expected behavior: Functional but may experience some lag
329+
- Use case: Deeply nested organizational structures, multi-tier architectures
330+
331+
{{< alert type="info" title="Testing Approach" >}}
332+
Start with the baseline scenario and progressively increase complexity. This helps identify the specific point where performance begins to degrade.
333+
{{< /alert >}}
334+
335+
### Target Metrics
336+
337+
Aim for the following performance targets when testing:
338+
339+
#### Frame Rate During Drag Operations
340+
- **Target**: 60 FPS (frames per second)
341+
- **Acceptable Threshold**: 30 FPS
342+
- **Below Threshold**: Indicates performance issues requiring optimization
343+
344+
#### Time to First Badge Render
345+
- **Target**: < 100ms
346+
- **Measurement**: Time from design load to all visible badges rendered
347+
- **Impact**: Affects perceived load time and user experience
348+
349+
#### Badge Re-renders Per Drag Operation
350+
- **Target**: < 1,000 re-renders
351+
- **Measurement**: Total badge rendering calls during a single drag operation
352+
- **Impact**: Directly affects drag smoothness and responsiveness
353+
354+
### Monitoring Performance
355+
356+
To monitor performance during testing:
357+
358+
1. **Browser DevTools**: Use the Performance tab to record and analyze interactions
359+
2. **Frame Rate**: Monitor FPS during drag operations
360+
3. **CPU Usage**: Watch for excessive CPU spikes during interactions
361+
4. **Memory Usage**: Check for memory leaks during extended sessions
362+
363+
{{< alert type="warning" title="Browser Differences" >}}
364+
Performance can vary significantly across browsers. Test in your primary target browsers (Chrome, Firefox, Safari) to ensure consistent experience.
365+
{{< /alert >}}
366+
367+
## Long-term Architecture Recommendations
368+
369+
While current optimizations provide significant performance improvements, several architectural enhancements could provide even greater benefits in future versions of Kanvas.
370+
371+
### Canvas-Based Badge Rendering
372+
373+
Migrating from DOM-based badge rendering to canvas-based rendering could provide 10-100x performance improvement:
374+
375+
**Current Approach (DOM-based):**
376+
- Each badge is an HTML element
377+
- Browser must manage layout, styles, and reflows
378+
- Limited by DOM manipulation performance
379+
380+
**Proposed Approach (Canvas-based):**
381+
- Badges rendered directly to canvas
382+
- No DOM manipulation overhead
383+
- Batch rendering operations
384+
- Better control over rendering pipeline
385+
386+
**Expected Benefits:**
387+
- 10-100x faster badge rendering
388+
- Reduced memory footprint
389+
- Smoother animations and transitions
390+
- Better scaling for large designs
391+
392+
### Virtual Badge Manager
393+
394+
A virtual badge manager would only render badges currently visible in the viewport:
395+
396+
**Implementation Strategy:**
397+
- Track viewport bounds
398+
- Maintain a spatial index of badge positions
399+
- Render only badges intersecting with viewport
400+
- Update dynamically as viewport changes
401+
402+
**Expected Benefits:**
403+
- Constant rendering time regardless of total badge count
404+
- Seamless handling of designs with thousands of nodes
405+
- Reduced GPU memory usage
406+
- Improved scrolling and panning performance
407+
408+
### Web Worker Rendering
409+
410+
Offloading computationally intensive operations to background threads (Web Workers) could prevent UI blocking:
411+
412+
**Candidate Operations:**
413+
- Badge layout calculations
414+
- Relationship path computations
415+
- Validation and feasibility checks
416+
- Complex selector evaluations
417+
418+
**Expected Benefits:**
419+
- UI thread remains responsive during heavy computations
420+
- Better multi-core CPU utilization
421+
- Smoother user experience during intensive operations
422+
- Reduced perceived lag
423+
424+
{{< alert type="info" title="Future Enhancement" >}}
425+
Web Worker rendering requires careful coordination between threads and may introduce complexity in state management.
426+
{{< /alert >}}
427+
428+
### Progressive Rendering Strategy
429+
430+
Implement a priority-based rendering system that renders critical elements first:
431+
432+
**Rendering Priority Levels:**
433+
1. **Critical (Immediate)**: Error badges, validation warnings
434+
2. **High (< 50ms)**: Info badges, relationship indicators
435+
3. **Medium (< 200ms)**: Annotations, secondary labels
436+
4. **Low (Idle Time)**: Decorative elements, optional metadata
437+
438+
**Expected Benefits:**
439+
- Faster time to interactive
440+
- Critical information always visible
441+
- Better perceived performance
442+
- Graceful degradation under load
443+
444+
{{< alert type="success" title="User-Centric Design" >}}
445+
Progressive rendering ensures users see the most important information first, even if the design hasn't fully loaded.
446+
{{< /alert >}}
447+
448+
## Performance-Related URL Parameters
449+
450+
Kanvas supports several URL parameters that can impact rendering performance and behavior. Understanding these parameters helps you optimize the loading and rendering of your designs.
451+
452+
### Full Render Mode
453+
454+
The `render=full` URL parameter enables comprehensive rendering of all design elements, including advanced relationships:
455+
456+
**Usage:**
457+
```
458+
https://cloud.layer5.io/kanvas/designer?design=<design-id>&render=full
459+
```
460+
461+
**What It Includes:**
462+
- All component relationships
463+
- TagSet relationships and groupings
464+
- Advanced semantic relationships
465+
- Complete metadata rendering
466+
- All badges and indicators
467+
468+
**Performance Implications:**
469+
- Increased initial load time
470+
- Higher memory usage
471+
- More computational overhead during updates
472+
- May impact performance on large designs (100+ components)
473+
474+
{{< alert type="warning" title="Large Design Consideration" >}}
475+
For designs with hundreds of components or complex TagSet relationships, full render mode may cause noticeable performance impact. Consider using standard render mode and selectively enabling layers as needed.
476+
{{< /alert >}}
477+
478+
### Additional Parameters
479+
480+
For complete documentation on all available URL parameters and their effects, see [URL Parameters](/kanvas/advanced/url-parameters/).
481+
482+
{{< alert type="note" title="Parameter Combinations" >}}
483+
URL parameters can be combined to customize your Kanvas experience. Experiment with different combinations to find the optimal balance between features and performance for your specific use case.
484+
{{< /alert >}}

0 commit comments

Comments
 (0)