Improve startup time of the display sample under MSW

Performance tweak for samples/display, resulting in a much faster
application start, particularly when built in debug mode, when Windows
messages are dumped to the system debug channel for
inspection/diagnosis.

Speed up the Append() loop below by foregoing the repeated resizing of
the choice drop-down via repeated calls to GetBestSize() which happens
deep inside the Append() call chain and executes another inner loop
calling SendMessage() to get the control contents. (This exhibits
1/2*O(N^2) behaviour thanks to the linear growth of the length of the
inner loop to the length of the outer loop (= number of items to add),
while it is re-executed for every new added item.)

With the 'display' sample, that's about 500+ rounds and about 500*500/2
SendMessage() calls less now on my dev/test rig, taking noticeable time
to start the display application.

---

Issue was found due to the barrage of '(winmsg)' Windows Message debug
log lines zipping by in the monitor app when the sample was build in
Debug Mode. Only significant difference with the Release Build is those
debug lines being output, hence the performance gain is less, but still
measurable, in a Release build. When the machine is otherwise severely
loaded (UI render core maxing out), "measurable" becomes "obnoxiously
noticeable" again on Win10/64.

Closes #22049.
This commit is contained in:
Ger Hobbelt
2022-01-23 14:10:22 +01:00
committed by Vadim Zeitlin
parent 224d8ffdaf
commit 4902b8137b

View File

@@ -28,6 +28,7 @@
#include "wx/artprov.h"
#include "wx/bookctrl.h"
#include "wx/sysopt.h"
#include "wx/wupdlock.h"
#include "wx/display.h"
@@ -307,6 +308,17 @@ void MyFrame::PopuplateWithDisplayInfo()
#if wxUSE_DISPLAY
wxChoice *choiceModes = new wxChoice(page, Display_ChangeMode);
{
// Speed up the Append() loop below by foregoing the repeated resizing
// of the choice dropdown via repeated calls to GetBestSize() which
// happens deep inside the Append() call chain and executes another
// inner loop calling SendMessage() to get the control contents.
//
// As there can be a couple of hundreds of video modes, this saves
// many thousands of such calls and so has a very noticeable effect.
wxWindowUpdateLocker lockUpdates(choiceModes);
const wxArrayVideoModes modes = display.GetModes();
const size_t countModes = modes.GetCount();
for ( size_t nMode = 0; nMode < countModes; nMode++ )
@@ -316,6 +328,8 @@ void MyFrame::PopuplateWithDisplayInfo()
choiceModes->Append(VideoModeToText(mode),
new MyVideoModeClientData(mode));
}
} // Destroy wxWindowUpdateLocker to finally resize the window now.
const wxString currentMode = VideoModeToText(display.GetCurrentMode());
choiceModes->SetStringSelection(currentMode);