[IronPython] Performance str.replace in Silverlight

Michael Foord fuzzyman at voidspace.org.uk
Tue Jun 1 23:46:51 CEST 2010


On 01/06/2010 21:11, Dino Viehland wrote:
> Michael wrote:
>    
>> 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')
>>      
> Couple of follow up questions (a simple repro isn't working for me):
> 	Is this on your Mac?
> 	What locale is your machine set to?  I'm guessing it's something like
> en-UK (or whatever the Mac equivalent is if it's different) or do you have it
> set to a German locale?
>
> If you're willing to try an experiment to re-build IronPython you could try
> changing the "v.IndexOf(oldString, start)" call in StringOps.cs to be:
>
> v.IndexOf(oldString, start, StringComparison.Ordinal)
>
> I think that's the only culture sensitive code path in our replace
> Implementation and so my guess is that's the problem.  If you can't rebuild
> and try it out I can probably track down a Mac to try the repro on.
>
>    

Yes, sorry - it is with Silverlight 4 and IronPython 2.6.1 on the Mac. 
It reproduced for both myself (English locale) and on my colleague who 
has a German machine. I don't know how easy it is to compile IronPython 
for Silverlight - it certainly wasn't easy a while ago but I can try 
again. :-)

All the best,

Michael



> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>    


-- 
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 Ironpython-users mailing list