[Mono-bugs] [Bug 77382][Min] New - System.Uri ctor could be faster

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Jan 27 05:08:48 EST 2006

Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by pawel.sakowski at mind-breeze.com.


--- shadow/77382	2006-01-27 05:08:47.000000000 -0500
+++ shadow/77382.tmp.6522	2006-01-27 05:08:47.000000000 -0500
@@ -0,0 +1,41 @@
+Bug#: 77382
+Product: Mono: Class Libraries
+Version: 1.1
+OS: GNU/Linux [Other]
+OS Details: 
+Status: NEW   
+Priority: Minor
+Component: System
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: pawel.sakowski at mind-breeze.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+Summary: System.Uri ctor could be faster
+According to heap-buddy, a single invocation of new
+Uri("http://something/") allocates 25 objects (a couple more if NET_2_0).
+If used frequently in a performance-critical environment, it places a
+non-negligible burden on the GC.
+A patch that follows reorganizes the code to make some savings. In the
+simple test case above, it saves 6 allocations. It basically does it by:
+- Avoiding allocating intermediate URI splitting results, use the
+string.IndexOf(string,int,int) method family on the original string.
+- Invocations of string.StartsWith(string) have under some circumstances
+(not the one described above) proven to allocate a long series of objects,
+the backtraces pointing to Mono.Globalization.Unicode.*. Since StartsWith
+it basically used within Uri to check for a short, constant prefix, I
+replaced it with explicit checks of individual characters.
+Other than improving the performance, the patch does not change the
+behavior of the class. One exception is that StartsWith is
+culture-dependent and under some cultures it might behave differently than
+character-by-character comparison. However, in such unlikely case I believe
+ that the culture-independent behavior is the one expected for System.Uri
+to exhibit.

More information about the mono-bugs mailing list