pragmagic / vscode-nim

An extension for VS Code which provides support for the Nim language.
Other
237 stars 37 forks source link

Something eats up a lot of time #44

Closed RSDuck closed 7 years ago

RSDuck commented 7 years ago

It looks like that something(probably the RPC library) eats up a lot of time. At first I thought the problem is related to nimsuggest but it isn't(https://github.com/nim-lang/nimsuggest/issues/55)

In all tests I used the following file: y.nim

import opengl

I added the following code to measure the performance within the extension:

let startTime = Date.now();
let ret = await desc.rpc.callMethod(new elparser.ast.SExpSymbol(NimSuggestType[suggestType]), normalizedFilename, line, column, dirtyFile);
let endTime = Date.now();
console.log("Request time: " + (endTime - startTime))

I moved the cursor into the third line of y.nim and it took it outputted a request time of around 7 seconds.

The I tried the following test program(it needs nimsuggest to be started with the arguments --port:2811 y.nim):

import times, net

var 
    line = ""
    totalTime = 0'f32
    measured = 0
for i in 0..2:
    var socket = newSocket()
    socket.connect("127.0.0.1", Port(2811))
    let startTime = cpuTime()
    socket.send("sug y.nim:3:0\n")
    var responseLines = 0
    while true:
        socket.readLine(line, 1000)
        if line == "":
            break
        inc(responseLines)
    let endTime = cpuTime()

    echo "Duration: ", (endTime - startTime) * 1000'f32, "ms"
    echo "Got ", responseLines, " results"
    totalTime += (endTime - startTime)
    inc(measured)

echo "Average time: ", totalTime / measured.toFloat * 1000'f32, "ms"

And it outputted always something like this:

Duration: 496.0ms
Got 8708 results
Duration: 427.0000000000001ms
Got 8708 results
Duration: 236.9999999999999ms
Got 8708 results
Average time: 386.6666555404663ms

So as you can see it isn't nimsuggests fault. I'm thinking the problem is related to elrpc but I'm not sure about this.

RSDuck commented 7 years ago

I've put some further research into it and created a version of vscode-nim which uses the "old" socket based protocol instead of epc and it's actually much faster(the code is mostly from an old version of vscode-nim which used this protocol): https://github.com/RSDuck/vscode-nim/tree/oldsockets

gif4 vs: gif5

EDIT: the question is now, what would be the best option? Switching back to tab based protocol or doing something to improve the performance of the EPC/RPC library(maybe it's the SExp library which performance is that bad)?

kosz78 commented 7 years ago

The better option will be improve EPC because this protocol returns lenght of message that guarantee that we read full message

RSDuck commented 7 years ago

already fixed with #48, I forgot to close it