[IronPython] Performance str.replace in Silverlight

Michael Foord michael at voidspace.org.uk
Thu May 27 09:41:28 PDT 2010


Hey guys,

I just tracked down a really nasty performance bug in our Silverlight 
application. It turned out that doing a simple string replace in a 400 
character string was taking 700ms. As we actually do two replaces and 
the text is usually substantially longer this was a real problem.

I fixed the problem by switching to explicitly calling the .NET 
String.Replace instead of str.replace, so it looks like an IronPython 
issue. It doesn't happen with *all* text, but it looks like non-ascii 
exacerbates the problem.

The particular text that triggered it was:

Die Neuanlage einer Welle muss auch zu Einträgen in der Tabelle 
dbo_tv_wellenwebsitesfirmenverbinder führen. Dabei werden die 
Zuordnungen aus der Vorwelle bei der Neuanlage einer neuen Welle 
einmalig übernommen. Jede Zeile der Vorwelle wird also kopiert und die 
Kopie erhält die Welle_uniqueID der neuen Welle. Die Verbindung zwischen 
Website_uniqueID <-> Firmen_uniqueID <-> FirmenAbrechnung_uniqueID 
bleibt somit erhalten.

The replace code was:

text = text.replace('\r\n', '\n').replace('\r', '\n')

The fix was:

text = String.Replace(text, '\r\n', '\n')
text = String.Replace(text, '\r', '\n')

All the best,

Michael Foord

-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.




More information about the Users mailing list