Earlier today I checked in a performance optimization to 
MIME_ConvertCharset()

Here are the general lessons I learned, details to follow.

1) Use quantify.  It's a great tool.  Read waterson's performance juju 
doc (http://www.mozilla.org/performance/profiling-juju.html).

2) jprof is useful, easier to get working than Quantify, but the data 
isn't as useful.  One feature that is missing is pause,resume,rewind.  
If we had a way to stop recording, resume recording, and rewind (forget 
all previous recorded data), jprof would be *really useful.  I'll log on 
this to track it.

3) For those of you who have datasources:  if you notice you are calling 
GetTarget() on a datasource a lot, worry about optimizing the case where 
GetTarget() gets a target (doesn't return NS_RDF_NO_VALUE).  My 
experience with the mail news datasources is that calls to GetTarget() 
that don't get a target aren't expensive.  The ones that do return a 
target, do all the work.

4) after you quantify, see who is calling 
nsComponentManager::CreateInstance().  Unlike GetService(), tons of 
calls to CreateInstance() will mean tons of allocations.  I found our 
problem with MIME_ConvertCharset() when I saw that we were creating and 
initializing an expensive object over and over when we didn't need to.


Here are the specific details of the optimization for MIME_ConvertCharset()

Coverting from UTF-8 to UTF-8, us-ascii to UTF-8, and us-ascii to UTF-8 
are all no-ops.  We were allocating and initializing a 
MimeCharsetConverterClass object each time MIME_ConvertCharset() was 
called.  This code gets called when sorting the thread pane (by sender), 
scrolling the thread pane, and in message display.  Especially for you 
english users, less so if you are non-english user.  But still a lot, 
since headers frequently don't need conversion.

I added some code to quickly bail out in the no-op case.  There are bugs 
logged to avoid some of the string copying going on, and to get create 
as few MimeCharsetConverterClass objects as possible.  In most cases, 
english users or non-english users, you should only need to create a 
very small number.

-Seth


Reply via email to