Very slow user.Current() on Windows

418 views
Skip to first unread message

Alexey Borzenkov

unread,
Apr 16, 2013, 5:28:18 PM4/16/13
to golang-nuts
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.

al...@zor.io

unread,
Sep 8, 2013, 3:15:53 AM9/8/13
to golan...@googlegroups.com
Yucky - just ran in to this.

Is this worth a bug report? I see there's another similar thread (https://groups.google.com/forum/?fromgroups#!searchin/golang-nuts/user.Current/golang-nuts/ytO9gCj2gqI/F69jRq9FdV0J) and it seems like Windows is somehow to blame - well, whatever.

However, I only need the user profile directory, which I can get by calling syscall.OpenCurrentProcessToken()...GetUserProfileDirectory() without the other (problematic) calls done by user.Current(). Certainly this approach beats sniffing the OS and using ENV variables.

Alex

Dave Cheney

unread,
Sep 8, 2013, 3:27:08 AM9/8/13
to al...@zor.io, golang-nuts
I believe this was issue,
https://code.google.com/p/go/issues/detail?id=5298. This was comitted
after Go 1.1 was branched and will be in Go 1.2. If you are able,
please compile tip from source and try again. If the issue still
occurs, please open a new issue.
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Alex Zorin

unread,
Sep 8, 2013, 3:29:22 AM9/8/13
to golan...@googlegroups.com, al...@zor.io
Thanks Dave. I absent-mindedly searched in "Open Issues" and didn't see it. Looking forward to 1.2.

Alex
Reply all
Reply to author
Forward
0 new messages