Tuesday, September 15, 2009

Performance issue using SPUtility.GetFullNameFromLogin

Recently we had a strange support call regarding our rating solution.

The customer experienced very bad performance using our rating field type, when opening the comments page for an item.

everything else was working very fast, pages loaded within a blink of an eye, only opening the popup that displays the comments and ratings from other users took anywhere from 10 to 40 seconds...

So, we created a debug version that prints out the time stamp of every stage of the page.
What the page does is basically, load all comments and ratings into a list and binds them into a repeater control.

So, we found out that while loading the comments we get the user login name, and since we want to show the user display name we use this SharePoint API method to get the display name from the login name:
SPUtility.GetFullNameFromLogin(site, "domain\\user_login");

well, to keep it simple, calling the method above to get the user display name took 8 seconds every time we called it, so for every comment on the item the page load time would take 8 more seconds!!!

The customer opened a support call to microsoft while we were investigating other alternatives for getting the user display name.

The answer the customer got from microsoft team was simple and did resolve the issue.
Simply instead of using SPUtility.GetFullNameFromLogin, they recommend using:


so, the web.EnsureUser method works much faster and the performance problem was resolved!

Since I did not see any post about this on the web I thought I might as well write one myself - hope this helps some of you in the future.

Shai Petel.


John said...

I recently read about a SharePoint performance accelerator, called aptimize (I think) - MS are apparently using it on their own SP installation to increase overall performance - looks very interesting if it really "does what it says on the tin" - how do you rate it?

Robin said...

The reason why it's taking ages to get the name back from the SPUtility method is due to the customer's AD. Since the query is being fired against AD.. so you can imagine if there are a lot of DC's and trusted domains (typically seen at enterprise customers) it takes a lot of time to resolve the user. Microsoft uses the same query when you try to add an user or group to the site using the UI. If you time it, you will see that it takes the same amount of time as it does in your code..

Josh Korn said...

We have a relatively small AD, and not only did GetFullNameFromLogin perform poorly, it also occasionally failed on what Windows called a "Method Invocation Exception" (which obviously isn't much help to us).

Reflector code for GetFullNameFromLogin seemed to indicate that it was using the COM behemoth, so that also contributed to the slow performance.

Web.EnsureUser works directly from internal tables, and is fast enough that you don't have to think twice about using it. It does have drawbacks, documented elsewhere, but unless you encounter those, it's the way to go.

Thanks for this post.