Adam Driscoll
Adam Driscoll

Reputation: 9483

LookupAccountSid taking +600 ms per call

I'm using GetTokenInformation with the TokenGroups flags to retrieve all the groups that a particular token is part of. I'm then looping through each of the returned SIDs and using LookupAccountSid to grab the user name and domain. I call LookupAccountSid twice: the first time to grab the size of the name and domain character arrays and the second time populates the allocated StringBuilders.

I'm getting very long delays. I've run ANTS to see what the issue was and found that if a user was part of 23 groups this that the entire sequence would take 15 seconds! The profiler points to the first call of LookupAccountSid and states that it was averaging 652 ms per call.

This is what the call looks like:

            LookupAccountSid(null, tokenGroups.Groups[i].SID, null, ref accountCount, null,
                             ref domainCount, out snu);

accountCount and domainCount are initialized to 0 prior to this call. In the end the call is working but this delay is way to long. What am I doing wrong?

Upvotes: 2

Views: 625

Answers (1)

leppie
leppie

Reputation: 117280

It is impossible to accurately measure time taken when running a profiler.

It is only useful when compared to all the times of other methods.

Run the call using Stopwatch as a timer without debugging info/attaching a debugger, and optimizations turned on.

Edit:

I have code that runs about 100 times longer when a profiler is attached (10 seconds) vs NGEN'd app (0.1 seconds).

Upvotes: 3

Related Questions