Hi,
I was using
github.com/lib/pq at home today to compare some performance numbers, when I noticed numbers I was getting were much lower than expected. Upon investigation I found that pq tries to get current username on every connect, for which it uses os/user. Turns out on my Windows machine (Windows 7 x64 Home Premium) the call to user.Current() TAKES 4 SECONDS to return. :(
Investigating further showed that all that time is spent in syscall.TranslateAccountName, which is a wrapper around TranslateName API. Now, that API is for Directory Services, and my machine is obviously not in a domain, so domainAndUsername is COMPUTERNAME\username. I can only assume that it's actually trying to find COMPUTERNAME domain and times out.
The obvious question is why does os/user/lookup_windows.go is checking domain name first (when not every computer is in a domain obviously), instead of using NetUserGetInfo and only if that fails resorting to potentially slower TranslateAccountName?
Best regards,
Alexey.