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

user.LookupID() is extremely slow #8264

Closed
gopherbot opened this issue Jun 22, 2014 · 3 comments
Closed

user.LookupID() is extremely slow #8264

gopherbot opened this issue Jun 22, 2014 · 3 comments

Comments

@gopherbot
Copy link

by mmstickman:

Go v1.3

I'm writing a program that imitates, ls, and when printing files in long mode and
converting uids to usernames with user.LookupID(uid), it requires a significant amount
of computational time to complete.

An example is that it takes 250 milliseconds to process all of the entries in /usr/bin
versus 50 milliseconds without. When doing the same for /, it takes 1600 usec to convert
and print user/groupnames versus 300 usec printing uid/gid's directly.

Code is attached; you can switch from printing ids to names by modifying the getUID and
getGID functions, which return 'return fmt.Sprintf("%d",
file.Sys().(*syscall.Stat_t).Uid)' to 'return idToName(fmt.Sprintf("%d",
file.Sys().(*syscall.Stat_t).Uid))

Attachments:

  1. ls.go (15571 bytes)
@ianlancetaylor
Copy link
Contributor

Comment 1:

user.LookupID is calling into the C library to convert user IDs to user names.  This is
because many of the details of that conversion are system dependent, such as the
possible use of LDAP.  If you are running on GNU/Linux, look at /etc/nsswitch.conf.
It is unlikely that there is anything we can do in this area.  If you have specific
suggestions, we'd be happy to hear them.

Status changed to Unfortunate.

@gopherbot
Copy link
Author

Comment 2 by mmstickman:

Would it be possible to have it check for such situations beforehand, and obtain those
names based off what is available? Such as parsing /etc/group and /etc/passwd directly
without using a C library if LDAP is not in use?

@minux
Copy link
Member

minux commented Jun 22, 2014

Comment 3:

As Ian said in #2, the correct way to go is to fix the configuration
(/etc/nsswitch.conf). e.g. list "files" first if that's what you want.

@golang golang locked and limited conversation to collaborators Jun 25, 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

3 participants