# HG changeset patch # User Siddharth Agarwal # Date 1429133744 25200 # Node ID f2fd087a75ef4bce92746a1f4cd03661946b999f # Parent 07200e3332a169cbbcc8a9fdc1134196c1e1ce22 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) diff -r 07200e3332a1 -r f2fd087a75ef mercurial/parsers.c --- 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;