On Fri, 2009-09-11 at 10:42 +1000, Alexander Kojevnikov wrote:
> 2009/9/11 Bertrand Lorentz <bertrand lorentz free fr>:
> > Hi,
> >
> > I'm a bit late, but I'd like to point that the patch below potentially
> > causes a lot of additional method calls and string allocations.
> >
> > I did a quick profiling session, doing these actions : start banshee,
> > scroll the listview of my whole library (about 2000 tracks), quit
> > banshee.
> > Here are the relevant parts of the "mono --profile" output.
> >
> > Before the patch :
> >
> > Time(ms) Count P/call(ms) Method name
> > ########################
> > 44.652 14484 0.003 System.String::Replace(string,string)
> > Callers (with count) that contribute at least for 1%:
> > 14032 96 %
> > NDesk.DBus.MatchRule::Append(StringBuilder,string,string)
> > 248 1 %
> > Mono.Addins.Database.ProcessProgressStatus::Decode(string)
> > 149 1 %
> > Banshee.GnomeBackend.GConfConfigurationClient::CreateKey(string,string)
> >
> > Total mem Method
> > ########################
> > 933 KB System.String::ReplaceUnchecked(string,string)
> > 933 KB 14335
> > System.String
> > Callers (with count) that contribute at least for 1%:
> > 14484 100 % System.String::Replace(string,string)
> >
> >
> >
> > After the patch :
> >
> > Time(ms) Count P/call(ms) Method name
> > ########################
> > 221.986 110715 0.002 System.String::Replace(string,string)
> > Callers (with count) that contribute at least for 1%:
> > 96231 86 %
> > Hyena.Data.Gui.ColumnCellText::UpdateLayout(Layout,string)
> > 14032 12 %
> > NDesk.DBus.MatchRule::Append(StringBuilder,string,string)
> >
> > Total mem Method
> > ########################
> > 1833 KB System.String::ReplaceUnchecked(string,string)
> > 1833 KB 42548
> > System.String
> > Callers (with count) that contribute at least for 1%:
> > 110715 100 % System.String::Replace(string,string)
> >
> >
> > This is of course very un-scientific, but I thought I'd throw it out
> > there, so that maybe someone would come up with a way to optimize this.
> >
>
> Thanks Bertrand, I didn't know about the --profile option, it looks very useful.
>
> I tried to substitute the String.Replace with a Regex.Replace using a
> pre-compiled regex. This ends up being an order of magnitude slower.
>
> However, if I check the string for \r or \n using
> String.IndexOfAny(char[]), the results are much better. I will commit
> this, let me know if you see different results.
>
> Cheers,
> Alex
After your commit, the same unscientific profiling shows both method
calls and memory allocation back to where they were before.
Of course, String.IndexOfAny(char[]) now gets called a lot more, but
it's fast and doesn't allocate much memory :
Time(ms) Count P/call(ms) Method name
########################
36.817 36804 0.001 System.String::IndexOfAny(char[])
Callers (with count) that contribute at least for 1%:
30678 83 %
Hyena.Data.Gui.ColumnCellText::UpdateLayout(Layout,string)
It doesn't even show up in the allocation profiler.
Thanks for the quick fix Alex !
--
Bertrand Lorentz <bertrand lorentz gmail com>
> http://flickr.com/photos/bl8/ <
Attachment:
signature.asc
Description: This is a digitally signed message part