When trying to log in as superuser and having thousands of websites listed. the system is tremendously slow. the reason seems to be line 82 in /core/View.php
the function usort is being used and the sort is very slow causing the many timeouts.
Maybe sort in db? or in other efficient way?
Let's try that again in a code block:
usort($sites, create_function('$site1, $site2', 'return strcasecmp($site1["name"], $site2["name"]);'));
I don't think that line of code is the bottleneck.
I just ran a simulation using 23,000+ domain names. Before my optimization: 2.83 seconds; After: 1.89 seconds.
What server side errors are you seeing?
I get this message: Allowed memory size of X bytes exhausted (tried to allocate Y bytes )...
the only thing that helped me "solve" the problem is to give up the sorting.
We have over 80K sites listed and growing. and it is impossible to sort them this way.
After all the sorting is for the admin interface and in our case is less important.
I also disabled the option of showing the drop down by turning $showSitesSelection to false
So even when i use the admin to see data, i will not load all these sites into the dropdown.
This is pretty much solved my problems. thx
Yes, 80K domains would be a problem. The memory exhausted error depends on your memory_limit in php.ini. My test with 23,000 domains maxed out my 32MB limit, which is around the norm. Using strcasecmp() instead of strtolower() would eliminate a lot of string conversions and small string allocations, but transferring 80K domains for the site selection list would still take a hit.
FYI showSitesSelection is set to true in several places:
plugins/Widgetize/templates/index.tpl plugins/Live/templates/index.tpl plugins/CoreHome/templates/index.tpl plugins/API/templates/listAllAPI.tpl
I'd like to propose adding a config option (e.g., threshhold) to accommodate larger installations like yours.
Fixed in 
fix #495 Adding option in configuration file: show_website_selector_in_user_interface
; if set to true, the website selector will be displayed in the Piwik UI
; if your Piwik installation has thousands of websites, you may disable the website selector
; as it slows down the loading of the Piwik UI by setting this value to false
following vipsoft suggestion