Hello, My nim projects (quite small still below 500 CLOC) execute painfully slow and I have zero idea why. I installed nim 0.20.0 using choosenim (the installation was quite slow too). This has happened on Fedora 30 and Void Linux so far. However, the same piece of code compiled with the same nim compiler version ran fine on a Proxmox (debian fork) server.
I'm not sure how to approach this problem, has anyone seen this before?
You would have to tell us more.
Ideally if you have a sample of code that exhibits that behaviour that would help a lot. There are just too many things that are involved in the perf results.
It could be Nim, it could be that you didn't compile with -d:release, it could be that your algorithm has bad asymptotic complexity, it could be that you are allocating strings or sequences in a tight loop and many more things.
I think the problem is within the httpClient library. Even this small snippet executes very slow:
import httpClient
let client = newHttpClient()
echo client.getContent("http://ident.me") # returns your ip
Neither d:danger or d:release helped. The original project I tried running was a telegram bot, which also uses httpClient.
That code executes in 0.1 sec in debug built on my box.
May there be something wrong with your local computer?
Maybe DNS resolution is really slow on your Fedora server?
Try changing the URL string ("http://ident.me") to an IP address ("http://176.58.123.25") to see if that speeds things up.
Antivirus? Net with QoS?
Try hitting localhost, and see if it changes. Whatsoever looks like a networking and related problem than a Nim code problem.
I didn't have any nameservers other than 192.168.0.1. I did try debugging it but I hit a bit of a roadblock. The problem seems to be in net.dial (called here: https://github.com/nim-lang/Nim/blob/devel/lib/pure/httpclient.nim#L928). Sadly I could not "debug" the net module, I tried downloading it from https://github.com/nim-lang/Nim/blob/devel/lib/pure/net.nim. But whenever I try to import it, it errors:
/home/kaletaa/Stuff/nim/performanceTest/localHttpClient.nim(960, 28) Error: type mismatch: got <localNet.SslContext, asyncnet.AsyncSocket, localNet.SslHandshakeType, system.string>
but expected one of:
proc wrapConnectedSocket(ctx: SslContext; socket: Socket;
handshake: SslHandshakeType; hostname: string = "")
first type mismatch at position: 2
required type: Socket
but expression 'client.socket' is of type: AsyncSocket
1 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them
expression: wrapConnectedSocket(client.sslContext, client.socket, handshakeAsClient,
connectionUrl.hostname)