Full disclaimer: I haven’t done any performance measurements myself so far, let alone actually implemented a “win32 event queue” application (I am still a mere couple of hours in my “proof of concept” application, which will basically record the flight track for later replay, that is at 30 Hz or higher (I have yet to figure out a meaningful sampling rate ;)).
So when I said “innefficient” my statement is mostly based on the official API documentation (which I quoted several times above) - and on common sense.
Because you seem to talk about a different aspect of the message processing: the processing of the message itself!
But that was not my point: my point is that at the time you have received the correspoding user event (via the Win32 event queue) you have already - potentially - wasted performace. Before you actually fetch the actual message (be it in the same or a separate thread). Why? Because the Win32 event queue itself is an “overhead”!
And that overhead only pays off if you expect messages infrequently (relatively speaking), or in other words: if you keep polling at a given rate and only get an actual message in 1 out of 10 cases, then your other 90% of “polling” (SimConnect_CallDispatch) calls are “wasted”. In this case the “event based processing” is better (including the overhead of the event queue).
If on the other hand you “catch” 9 messages in 10 “polls” (which implies that the messages arrive more or less at the same frequency as the “polling frequency”) then “polling” is more performant, because it does not involve the costly Win32 event queue (which might not even be there in the first place, e.g. if one wants to provide a “GUI-less” library without a Win32 event queue - so one would have to create a “virtual form” (invisible) simply to get access to the Windows event queue - or so I understand, I am not a “native win32 developer”, I am more proficient with Qt applications).
Again, how you process the message (in a separate “worker thread” or in the same thread) does not matter at this point, because all we are comparing at this point is “polling” vs “event-based message handling” (but yes, that is definitively a separate discussion which also may impact message handling performance, of course - and the same discussion applies exactly the same way for both “polling” and “event-based processing”).
So in your “client/server” use case the Win32 event queue approach may very well be suited better, because as you say, the client is expected to call the values relatively infrequently (at most up to a couple of times per second, maybe at a 6 Hz frequency or even less?). And as you say, the client may even be asking them “only once” (the fact that a lot of variables are requested at once does not matter that much, performance-wise).
Well, yes, my “flight recorder” scenario: there the aircraft’s position is expected to change every “simulated frame” So I would expect “polling” to be more performant than the “event-based processing”.
But yes, I still have to figure out a balanced (memory and CPU-wise) sampling frequency, because a) positions can be interpolated (during “playback”) and b) sampling at a 6 Hz rate (for both recording and playback) might be already sufficient, because I think FS 2020 “interpolates” (simulates) the aircraft’s position anyway, so (re-)setting the aircraft’s position 6 times a second (or even less, who knows…) might already be sufficient for a “smooth playback performance”.
And in the end it may as well turn out that an event-based processing may be (better) suited for my use-case scenario as well (I am still getting familiar with the API myself and am glad if things work at all ;)).
Oh and yes, I would be very interested in your “client/server” code as well (I have already looked at e.g. a “Python wrapper”, which seems to cache the received messages up to a user-defined interval (like “for two seconds” etc.). So I assume your server also has to cache the received messages (in a ring buffer etc.), until the client has fetched (“consumed”) them, right?
Btw my code will also be eventually made available on github