Bookmark multiple lines.
-
Have you got any idea about this behaviour ?
Neither do I, however I made a similar test with LuaScript and found I was able to mark the lines in less than ~150 milliseconds. To be clear, this is not completely a fair comparison as I am currently unable to run the PythonScript code in the same test environment (i.e. hardware, other plugins installed, N++ settings, etc). So it would be nice for someone to also try this LuaScript code:
for line_nbr = 100, 3899 do editor:MarkerAdd(line_nbr, 24) end
We’ve had some similar discussions before about how looking for markers can be slow
Searching for markers should be quite fast (e.g. using calls such as
SCI_MARKERNEXT
) but as I’m not aware of the previous discussion you have had regarding this issue and maybe I am completely off topic…so please disregard if that’s the case. :)a typical use might be creating a selection of a few dozen lines and bookmarking them
One use-case I could potentially see is marking all the lines in the file, then doing things like manually unmarking lines or ranges of lines.
-
As far as I understood, the main difference is, that python script uses the
SendMessage mechanism whereas Lua Script uses directFunctionPointer.SendMessage is known to be a little bit slow if it is called often.
Just an example, the same function called 10 times in a row@time_function() def test(): for line_nbr in range(100, 390): editor.markerAdd(line_nbr, 24)
results in
test((), {}) -> None took 3.8789999485 seconds test((), {}) -> None took 0.276999950409 seconds test((), {}) -> None took 1.06299996376 seconds test((), {}) -> None took 1.46799993515 seconds test((), {}) -> None took 2.19100022316 seconds test((), {}) -> None took 0.131000041962 seconds test((), {}) -> None took 0.480999946594 seconds test((), {}) -> None took 0.243000030518 seconds test((), {}) -> None took 1.80200004578 seconds test((), {}) -> None took 4.5720000267 seconds
In addition, python script is releasing the GIL explicitly before each SendMessage
call, but I guess this is a minor issue “performance-wise”.Cheers
Claudia -
Was curious so I did a bit more testing and wrote some C code and compiled it into a plugin:
- Using a direct pointer uses on average ~10ms to set 3800 bookmarks in the file.
- Using
SendMessage
uses on average ~17ms to set 3800 bookmarks in the file.
Note: I did this under a very uncontrolled test environment so these numbers should be seen as a rough idea how these two compare.
It would be interesting to set up better tests to compare performance between “a direct function pointer” vs SendMessage vs PythonScript vs LuaScript
-
nearly 2 times slower is huge but this doesn’t explain my numbers.
Did you run it multiple times? If yes, then there must be something in addition
which slows down with python script.Cheers
Claudia -
Yes I ran it numerous times and roughly averaged out the numbers I was seeing. Again this was a very rough test I did ;) I didn’t calculate a standard deviation but it was definitely much smaller than the results you were seeing with PythonScript.
-
@dail said that @scott-sumner said:
We’ve had some similar discussions before about how looking for markers can be slow
Aw, cmon @dail, your memory isn’t perfect? These discussions were here. I don’t have time to revisit looking at it now, but if my memory is OK, I remember that the marker searching logic that was fast didn’t exactly correspond with how the documentation says such searching should be done, but it worked.
-
Aw, cmon @dail, your memory isn’t perfect?
Oh how I wish. :)
Though that discussion was regarding indicators, this is just dealing with markers.
-
@dail said:
Though that discussion was regarding indicators, this is just dealing with markers.
Yea, my memory recall wasn’t perfect either, sigh…
-
Now I’m confused, running the same script on my old single core 1.5Ghz 32bit processor
with 32bit operating system results intest((), {}) -> None took 0.608999967575 seconds test((), {}) -> None took 0.733999967575 seconds test((), {}) -> None took 0.790999889374 seconds test((), {}) -> None took 0.677000045776 seconds test((), {}) -> None took 0.704999923706 seconds test((), {}) -> None took 0.678999900818 seconds test((), {}) -> None took 0.878000020981 seconds test((), {}) -> None took 0.634999990463 seconds test((), {}) -> None took 0.706000089645 seconds test((), {}) -> None took 0.753000020981 seconds
Previous result was an old dual core 2.0Ghz 64bit processor on 64bit operating system, but
using 32bit notepad++ (wine api layer issue??)Cheers
Claudia -
and now I’m …
lua_markerAdd took 0.11399999999958 seconds lua_markerAdd took 0.11599999999999 seconds lua_markerAdd took 0.11799999999948 seconds lua_markerAdd took 0.12899999999991 seconds lua_markerAdd took 0.11400000000049 seconds lua_markerAdd took 0.11599999999999 seconds lua_markerAdd took 0.11499999999978 seconds lua_markerAdd took 0.11400000000049 seconds lua_markerAdd took 0.11400000000049 seconds lua_markerAdd took 0.11499999999978 seconds py_markerAdd((), {}) -> None took 7.81100010872 seconds py_markerAdd((), {}) -> None took 7.80900001526 seconds py_markerAdd((), {}) -> None took 7.68000006676 seconds py_markerAdd((), {}) -> None took 8.02199983597 seconds py_markerAdd((), {}) -> None took 7.70700001717 seconds py_markerAdd((), {}) -> None took 7.73000001907 seconds py_markerAdd((), {}) -> None took 7.84200000763 seconds py_markerAdd((), {}) -> None took 7.71900010109 seconds py_markerAdd((), {}) -> None took 7.76399993896 seconds py_markerAdd((), {}) -> None took 7.83399987221 seconds
tested on same machine, with marking lines 100 to 3899
I mean, two times faster can be explained but 80 times faster.
There must be something specific which slows down the execution.Cheers
Claudia -
by using direct function pointer it is a little bit faster ;-)
DirectFunction took 0.111000061035 seconds DirectFunction took 0.147000074387 seconds DirectFunction took 0.148999929428 seconds DirectFunction took 0.146000146866 seconds DirectFunction took 0.154000043869 seconds DirectFunction took 0.271999835968 seconds DirectFunction took 0.24799990654 seconds DirectFunction took 0.164999961853 seconds DirectFunction took 0.164999961853 seconds DirectFunction took 0.171000003815 seconds
Cheers
Claudia -
and with some performance optimization, same test, same machine,
DirectFunction took 0.0729999542236 seconds DirectFunction took 0.0710000991821 seconds DirectFunction took 0.0720000267029 seconds DirectFunction took 0.0759999752045 seconds DirectFunction took 0.0729999542236 seconds DirectFunction took 0.0769999027252 seconds DirectFunction took 0.0739998817444 seconds DirectFunction took 0.0759999752045 seconds DirectFunction took 0.0759999752045 seconds DirectFunction took 0.0759999752045 seconds
Enough performance testing from my side :-)
Still curious why wrapped call is so slow.Cheers
Claudia -
Hello, @dail, @scott-sumner, @claudia-frank, and All,
Ah, I didn’t think that my slowness’s feeling, regarding that script, would lead to so many posts ;-))
I realize that I was quite vague, about the results of the test. So I did, again, the test with both :
-
Python
v1.0.8.0
-
Lua
v0.6.0.0
installed, in a N++
v7.4.2
local configuration, on a old Win XP SP3 platform, with 1Go of RAM, only !The python test script was :
for line_nbr in range(100, 12400): editor.markerAdd(line_nbr, 24)
And the Lua test script was :
for line_nbr = 100, 12400 do editor:MarkerAdd(line_nbr, 24) end
Results if applied on a classical .txt file, containing
12436
lines, with size =613,527
bytes :-
1m and 59s
for the Python script -
0.5s
, approximatively, for the Lua script
Really awesome, isn’t it ?! How to explain such a difference ??
BTW, Dail, I ran the command, below, in the Lua Console. Not sure, however, that it’s the right syntax !
dofile("Dail_Bookmark.lua")
Now, Dail, an other problem !
My first idea, for doing the test, was to install the Lua last version (
0.7.1.0
). Unfortunately, when starting N++, I got a tiny window, with the messageUnknown exception
. After validation, this windows disappeared but the lua plugin was not uploaded ( Quite sure that uploaded is not the right English word but I hope I will be understood ! ) That issue also occurs with thev0.7.0.0
version ! So, the last Lua plugin correct version isv0.6.0.0
, on my XP machine.Probably, this happens on Win WP platforms, exclusively ? But, dail, it’s not that important. Indeed, Don Ho, seemingly, considers not supporting, soon, Win XP, anymore ! Refer :
https://notepad-plus-plus.org/community/topic/15003/notepad-7-5-4-release/26
Nevertheless, thanks, by advance, for any investigation, on that matter !
Best Regards,
guy038
Update :
I’ve just done the test, twice, again, with the Python script ==> A bit better :
1m and 33s
, approximatively !! -
-
Some very interesting results for sure, I can’t say much as to why the PythonScript version is so much slower and I am very unfamiliar with the Python/C API. Maybe someone more knowledgeable has some ideas.
Unfortunately, when starting N++, I got a tiny window, with the message Unknown exception.
Sorry to hear the newer versions are not working for you, and I agree it is probably related to Windows XP. Between versions
0.6.0
and0.7.0
I did update to VS2015 and it also uses a newer runtime. Even though it is suppose to be compatible with XP there still seems to be a problem as you have found out. Personally I do not have access to an XP machine any more so any XP related issues will probably go unfixed unless someone submits a pull request fixing them. -
I don’t think file size matters, I did a test with a 100mb file as well as with
file containing just enough carriage returns -> result is the same.I haven’t found out yet why PythonScript(PS) is so slow in this case and it must be
something how PS handles the wrapped call because when using PS and the
Direct_Function call then I do get results like thisDirectFunction took 0.0729999542236 seconds DirectFunction took 0.0710000991821 seconds DirectFunction took 0.0720000267029 seconds DirectFunction took 0.0759999752045 seconds DirectFunction took 0.0729999542236 seconds DirectFunction took 0.0769999027252 seconds DirectFunction took 0.0739998817444 seconds DirectFunction took 0.0759999752045 seconds DirectFunction took 0.0759999752045 seconds DirectFunction took 0.0759999752045 seconds
Cheers
Claudia -
I did some poking around…and installed PythonScript (I haven’t used it in years). When I ran some test code, one of the first things I realized is that it is that Scintilla is being redrawn multiple times when using PythonScript. I verified this by catching the SCN_UPDATEUI event in Lua. The LuaScript call generates 1 event, using PythonScript generates numerous events…not always the same amount (normally about 50% of however many bookmarks were added). It probably also generates numerous SCN_MODIFIED events?
You might try a similar test with PythonScript which doesn’t generate any type of side effect, something simple like SCI_STYLEGETFORE which should be a very fast and simple call.
-
-
Good job, I guess that is the area which needs investigation, yes.
I tested with synchronous and asynchronous callbacks - result was more or less the same.If I
added markers for 30 lines it report one aditional updateui event,
adding markers to 290 lines it added 3 additional event
adding markers to 3800 lines it added 40 additional eventslua reported only 1 event in all cases, the same is true if using Direct_Function call.
Cheers
Claudia -
Hello, @dail,
Did you see that post :
It seems that @vitaliy-dovgan found out a solution, regarding VS2015 and the auto-detection problem, in XP
So, given that information, may be, after few modifications, we could have the Lua v7.0 and Lua v7.1 plugins working nice on XP platforms ? Just an intuition but I hope so !
Cheers,
guy038
-
Unfortunately I’m not sure if that’s the cause of issues with LuaScript running on XP. I know that the plugin itself doesn’t use that type of function call. I’m not sure if the Lua interpreter does underneath…if so it’s probably not something I care to dig into.
-
-