Just sharing here my tests...
I've been doing some benchmarking to compare Scintilla messaging performance using
ScintillaSendMessage() vs rirect calls with a prototype mapping to
SCI_GETDIRECTFUNCTION and even with
CallFunctionFast().
I'm using
ElapsedMilliseconds() to measure milliseconds differences in heavy For loops making message calls to Scintilla.
So far the performance differences are negligible: around 10 millisenconds for loops > 20000 — and these differences are most probably due to the OS doing other stuff in the background, because the values float from test to test. I doubt that any real case scenario would envolve more message calls than these tests.
But so fare I've only tested with
#SCI_APPENDTEXT messages. Not sure if dirrent messages can affect performance in different ways.
I was digging furture into Scintilla documentation on the issue:
http://www.scintilla.org/ScintillaDoc.html#DirectAccess
On Windows, the message-passing scheme used to communicate between the container and Scintilla is mediated by the operating system SendMessage function and can lead to bad performance when calling intensively. To avoid this overhead, Scintilla provides messages that allow you to call the Scintilla message function directly.
While faster, this direct calling will cause problems if performed from a different thread to the native thread of the Scintilla window in which case SendMessage(hSciWnd, SCI_*, wParam, lParam) should be used to synchronize with the window's thread.
This feature also works on GTK+ but has no significant impact on speed.
From version 1.47 on Windows, Scintilla exports a function called Scintilla_DirectFunction that can be used the same as the function returned by SCI_GETDIRECTFUNCTION. This saves you the call to SCI_GETDIRECTFUNCTION and the need to call Scintilla indirectly via the function pointer.
Scintilla documentation stresses in many places this overhead issue, and performance hit. Maybe on very old PCs it really does make a difference. But I can't measure any noticeable difference on my PC.
The last passage about
Scintilla_DirectFunction caught my attentions. Is this function available from PureBasic?
Can this function be imported accessed somehow?
Also, it seems that the performance issue is Windows-related only, and that direct calls are not a good idea when using threads.
So I guess that because of the latter
ScintillaSendMessage() must be mediated by MS Windows SendMessage functions, in order to work well with threads.