Performance Counters
ModernUI exposes optional performance counters on MuiRoot.
They are intended for development, stress testing, and support diagnostics.
They are not precise micro-benchmarks.
API
g_ui.PerfStatsEnabled(true);
g_ui.PerfStatsReset();
string summary=g_ui.PerfStatsSummary();
int drops=g_ui.PerfStatsEventQueueDrops();
Methods
| Method | Purpose |
|---|---|
PerfStatsEnabled(bool) |
Enable or disable performance stats |
PerfStatsReset() |
Reset counters to zero |
PerfStatsSummary() |
Return a human-readable one-line summary |
PerfStatsEventQueueDrops() |
Return dropped event count from the internal event queue |
Performance stats are off by default.
What counters include
The summary can include information such as:
- paint passes
- full repaint count
- partial repaint count
- layout passes per frame batch
- average paint duration
- max paint duration
- container child visits
- partial child skips
- child paints issued
- event queue drops
Exact text may change with the implementation, so do not parse the string as a stable API unless you control the library version.
Example logging
input bool InpPerfStats=true;
input int InpPerfLogSeconds=5;
datetime g_lastPerfLog=0;
void OnTimer()
{
g_ui.OnTimer();
if(InpPerfStats && TimeCurrent()-g_lastPerfLog>=InpPerfLogSeconds)
{
g_lastPerfLog=TimeCurrent();
Print(g_ui.PerfStatsSummary());
}
}
Event queue drops
Event queue drops mean input events were overwritten because the event queue filled under burst traffic.
int drops=g_ui.PerfStatsEventQueueDrops();
if(drops>0)
Print("ModernUI event drops: ",drops);
A small number during extreme stress testing may not matter. Drops during normal panel use should be investigated.
If drops appear during ordinary testing, consider increasing the event queue capacity passed to Init.
Timing limitations
PerfStatsSummary() uses MT5/Windows timing mechanisms.
The notes matter:
- timer resolution is often around 16 ms
- values are useful for trends, not exact micro-timing
- paint timing includes the CCanvas begin/end block
- chart redraw behaviour can affect perceived responsiveness
Use counters to compare changes, not to claim sub-millisecond performance.
Running with the stress test
Use:
Experts/ModernUI/Examples/ModernUI_Performance_StressTest.mq5
Suggested test flow:
- Enable performance stats.
- Attach the EA to a chart.
- Scroll large list/table controls.
- Drag sliders.
- Type in text boxes.
- Switch tabs.
- Resize the chart.
- Review Experts log output.
What to look for
Watch for:
- unexpected full repaints during small interactions
- high event queue drops
- high paint duration spikes during basic input
- repeated layout passes during scrolling
- stale pixels after partial invalidation
- native text host positioning issues
Common mistakes
Treating counters as precise benchmarks
They are indicative.
Enabling counters in every production EA
Use counters during development or when debugging user issues.
Ignoring event drops
Drops can mean input was lost under burst traffic. Investigate when they occur in normal use.
Related pages
- Rendering and invalidation
- Performance counters — instrument your own EA
- MuiRoot