Proposal: Performance Bottleneck Analysis & Optimization

What

Use tools like perf and flame graphs to identify and analyze performance bottlenecks during common editing scenarios in Mogan, and optimize the source code accordingly.

Why

Users running Mogan on older or low-power CPUs frequently report noticeable lag, especially when editing large documents or performing rapid input. By profiling and addressing the actual performance bottlenecks, we can significantly improve responsiveness and user experience, especially in educational or low-spec environments.

How

  1. Scripted Scenario Testing
  • Develop scripts to simulate common user interactions:
    • Opening large documents
    • Typing and deleting quickly
    • Switching between input modes (math, code blocks, lists, etc.)
    • Scrolling and navigation
  • Ensure coverage of high-frequency use cases.
  1. Performance Profiling
  • Use tools like perf record/report , Instruments on macOS, and flame graphs to identify high-cost functions.
  • Focus on system calls, memory allocations, redraw logic, and thread contention.
  1. Source Code Optimization
  • Based on profiling results, refactor C++ or Scheme source code:
    • Eliminate unnecessary memory copying or layout recomputation
    • Reduce redundant UI redraws
    • Improve data structures and algorithm efficiency
  • Benchmark performance before and after to verify the improvement.
  1. Regression Tests & Documentation
  • Create a basic performance regression test suite to prevent future slowdowns.
  • Document profiling methods and optimizations for future contributors.

I did some performance tuning on Mogan but find it hard to guarantee the correctness of the performance tuning.

For now, the smart font mechanism (I think) is the systematical root cause of the bad performance.

Other performance issues are related to specific use cases.