changeset 24736:f2fd087a75ef

parsers: when available, use a presized dictionary for the file foldmap On a repo with over 300,000 files, this speeds up perffilefoldmap: before: wall 0.178421 comb 0.180000 user 0.160000 sys 0.020000 (best of 55) after: wall 0.164462 comb 0.160000 user 0.140000 sys 0.020000 (best of 59)
author Siddharth Agarwal <sid0@fb.com>
date Wed, 15 Apr 2015 14:35:44 -0700
parents 07200e3332a1
children b061a2049662
files mercurial/parsers.c
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/parsers.c	Wed Apr 15 17:42:38 2015 -0400
+++ b/mercurial/parsers.c	Wed Apr 15 14:35:44 2015 -0700
@@ -205,7 +205,20 @@
 		goto quit;
 	}
 
+#if PY_VERSION_HEX >= 0x02060000
+	/* _PyDict_NewPresized expects a minused parameter, but it actually
+	   creates a dictionary that's the nearest power of two bigger than the
+	   parameter. For example, with the initial minused = 1000, the
+	   dictionary created has size 1024. Of course in a lot of cases that
+	   can be greater than the maximum load factor Python's dict object
+	   expects (= 2/3), so as soon as we cross the threshold we'll resize
+	   anyway. So create a dictionary that's 3/2 the size. Also add some
+	   more to deal with additions outside this function. */
+	file_foldmap = _PyDict_NewPresized((PyDict_Size(dmap) / 5) * 8);
+#else
 	file_foldmap = PyDict_New();
+#endif
+
 	if (file_foldmap == NULL)
 		goto quit;