Hasty Briefsbeta

Bilingual

Severe performance penalty found in VSCode rendering loop

6 months ago
  • #rendering-loop
  • #binary-heap
  • #performance-optimization
  • The primary bottleneck in the rendering loop is at /vscode/src/vs/base/browser/dom.ts:365, where the animation frame queue sorts on every iteration inside a while loop.
  • Current implementation has a complexity of O(n² log n) due to repeated sorting, impacting performance with 50+ view parts by wasting 1-2ms per frame.
  • Proposed solution is to replace the array-based queue with a binary min-heap, reducing complexity to O(n log n) and cutting queue overhead by 85-90% (~1.5ms → ~0.2ms).
  • Implementation involves creating a BinaryHeap class with push and shift operations that maintain heap properties, and updating the dom.ts file to use this new structure.
  • The binary heap automatically maintains priority order, eliminating the need for manual sorting and significantly improving performance.