Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/user: very slow user.Current() on Windows #5298

Closed
snaury opened this issue Apr 16, 2013 · 7 comments
Closed

os/user: very slow user.Current() on Windows #5298

snaury opened this issue Apr 16, 2013 · 7 comments

Comments

@snaury
Copy link
Contributor

snaury commented Apr 16, 2013

Package os/user has a very slow user.Current(). For example on my machine (Windows 7 x64
Home Premium), that is not part of a domain, the call takes approximately 4.5 seconds.

It turns that all that time is spent in syscall.TranslateAccountName, which when you
look at msdn
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms725484(v=vs.85).aspx) is for
Directory Services, and home workstations are not in a domain.

Perhaps it is better to use NetUserGetInfo first, and revert to TranslateAccountName
only if NetUserGetInfo fails, though I'm not yet sure what it returns when machine is in
a domain.
@bradfitz
Copy link
Contributor

Comment 1:

Labels changed: added os-windows.

Status changed to Accepted.

@snaury
Copy link
Contributor Author

snaury commented Apr 16, 2013

Comment 2:

Another idea: use GetNetworkParams
(http://msdn.microsoft.com/en-us/library/windows/desktop/aa365968(v=vs.85).aspx) to see
if computer is part of a domain, and only use TranslateAccountName if it is...

@alexbrainman
Copy link
Member

Comment 3:

@snaury, SGTM. Please, send the change :-). It is go1.1 waiting time, so we will
probably have to wait for after go1.1.
Thank you.
Alex

@snaury
Copy link
Contributor Author

snaury commented Apr 17, 2013

Comment 4:

OK, no need for GetNetworkParams, what I actually found works best is to just check
whether domain is the current computer name, and if it is not to bother with a domain
controller. I'll submit a CL for that shortly...

@alexbrainman
Copy link
Member

Comment 5:

patch for https://golang.org/cl/8541047/
Alex

Attachments:

  1. a.diff (6090 bytes)

@bradfitz
Copy link
Contributor

Comment 6:

Labels changed: added performance.

@alexbrainman
Copy link
Member

Comment 7:

This issue was closed by revision fae362e.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants