[Mono-bugs] [Bug 59537][Nor] Changed - improve NameTable performance
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Sun, 6 Jun 2004 10:52:50 -0400 (EDT)
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 atsushi@ximian.com.
http://bugzilla.ximian.com/show_bug.cgi?id=59537
--- shadow/59537 2004-06-06 10:12:08.000000000 -0400
+++ shadow/59537.tmp.27631 2004-06-06 10:52:50.000000000 -0400
@@ -90,6 +90,111 @@
someone will overload the Add with StringBuilder parameter?) . In
order to make the code resilient I think we should pay the performance
"fee" and perform a delegation to one ImplMethod. Afterall , the real
performance problems are not here, they are in System.Data (this is
why I rated the issue NORMAL and not CRITICAL)
+
+------- Additional Comments From atsushi@ximian.com 2004-06-06 10:52 -------
+I have three points to say.
+
+1) Again, we need concrete performance comparison data such as shown
+below.
+2) Our GC is convervative so that avoiding object creation is
+ much important than MS.NET that has generational GC.
+3) You should not set CRITICAL priority without reading what
+"priority" means. It is written in the page linked from the immediate
+side of the select box, no matter how big the performance difference is.
+
+
+// net nametable implementation
+using System;
+using System.Collections;
+namespace System.Xml
+{
+ public class NameTable : XmlNameTable
+ {
+ Hashtable table = new Hashtable ();
+
+ public NameTable () {}
+
+ public override string Add (string name)
+ {
+ int hash = name.GetHashCode ();
+ string ret = (string) table [hash];
+ if (ret != null)
+ return ret;
+ table [hash] = name;
+ return name;
+ }
+
+ public override string Add (char [] name, int start, int len)
+ {
+ return Add (new string (name, start, len));
+ }
+
+ public override string Get (string name)
+ {
+ int hash = name.GetHashCode ();
+ return (string) table [hash];
+ }
+
+ public override string Get (char [] name, int start, int len)
+ {
+ return Get (new string (name, start, len));
+ }
+ }
+}
+
+// comparison code
+
+using System;
+using System.Xml;
+
+public class Test
+{
+ public static void Main ()
+ {
+ long start = DateTime.Now.Ticks;
+ NameTable nt = new NameTable ();
+ char [] name = new char [] {'n', 'a', 'm', 'e', '0', '0', '0',
+'0', '0'};
+ AddBatch (nt, name);
+ AddBatch (nt, name);
+ Console.WriteLine (DateTime.Now.Ticks - start);
+ }
+
+ private static void AddBatch (NameTable nt, char [] name)
+ {
+ for (int i = 0x30; i < 0x3A; i++) {
+ name [4] = (char) i;
+ for (int j = 0x30; j < 0x3A; j++) {
+ name [5] = (char) j;
+ for (int k = 0x30; k < 0x3A; k++) {
+ name [6] = (char) k;
+ for (int l = 0x30; l < 0x3A; l++) {
+ name [7] = (char) l;
+ for (int m = 0x30; m < 0x3A; m++) {
+ name [8] = (char) m;
+ nt.Add (name, 0, 9);
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+// The result with new code:
+12020000
+Total time spent compiling 602 methods (sec): 0.07
+Slowest method to compile (sec): 0.01: System.Xml.XmlNameTable::.ctor()
+
+Total memory allocated: 13530 KB
+
+// The result with existing code:
+4810000
+Total time spent compiling 604 methods (sec): 0.1
+Slowest method to compile (sec): 0.01: System.DateTime::GetNow()
+
+Total memory allocated: 6880 KB
+