[Mono-bugs] [Bug 557093] New: System.IO.StringReader.ReadLine is very slow for a string using Unix line endings

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Nov 19 22:57:23 EST 2009


http://bugzilla.novell.com/show_bug.cgi?id=557093

http://bugzilla.novell.com/show_bug.cgi?id=557093#c0


           Summary: System.IO.StringReader.ReadLine is very slow for a
                    string using Unix line endings
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.4.x
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: brett at fogcreek.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Created an attachment (id=328572)
 --> (http://bugzilla.novell.com/attachment.cgi?id=328572)
Patch for StringReader.cs

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.5)
Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)

System.IO.StringReader.ReadLine will scan all the way to the end of a string
that is using Unix line endings, because it always searches for both CR and LF.
So reading all of a StringReader's lines using repeated calls to ReadLine is
O(n^2) on the number of characters in the file (if you figure that the number
of line endings is linear on the number of characters in the string). This is
making some things time out for us, so here is a patch that makes it only read
to the next CR or LF. 

I'm not up on how lots of string functions are implemented in Mono, so I may be
doing something silly here - anyway, it may not be great to create a new
2-character array every time for the IndexOfAny call, but this is simple and is
testing out faster for me.

Reproducible: Always

Steps to Reproduce:
1. Get a large string containing lots of unix line endings (4 megs will
illustrate this nicely).
2. Create a StringReader on this string
3. Read it out using StringReader.ReadLine until there's nothing left
Actual Results:  
Way slower than the same string with DOS line endings

Expected Results:  
About the same speed as with DOS line endings

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list