comparison mercurial/parsers.c @ 28386:1c658391b22f

parsers: optimize filtered headrevs logic The old native head revs logic would iterate over every node, starting from 0, and check if every node was filtered (by testing it against the filteredrevs python set). On large repos with hundreds of thousands of commits, this could take 150ms. This new logic iterates over the nodes in reverse order, and skips the filtered check if we've seen an unfiltered child of the node. This saves approximately a bagillion filteredrevs set checks, which shaves the time down from 150ms to 20ms during every branch cache write.
author Durham Goode <durham@fb.com>
date Tue, 08 Mar 2016 00:20:08 -0800
parents 90e3c5129226
children 507136150d2b
comparison
equal deleted inserted replaced
28385:3f9e25a42e69 28386:1c658391b22f
1444 if (nothead == NULL) { 1444 if (nothead == NULL) {
1445 PyErr_NoMemory(); 1445 PyErr_NoMemory();
1446 goto bail; 1446 goto bail;
1447 } 1447 }
1448 1448
1449 for (i = 0; i < len; i++) { 1449 for (i = len - 1; i >= 0; i--) {
1450 int isfiltered; 1450 int isfiltered;
1451 int parents[2]; 1451 int parents[2];
1452 1452
1453 isfiltered = check_filter(filter, i); 1453 /* If nothead[i] == 1, it means we've seen an unfiltered child of this
1454 if (isfiltered == -1) { 1454 * node already, and therefore this node is not filtered. So we can skip
1455 PyErr_SetString(PyExc_TypeError, 1455 * the expensive check_filter step.
1456 "unable to check filter"); 1456 */
1457 goto bail; 1457 if (nothead[i] != 1) {
1458 } 1458 isfiltered = check_filter(filter, i);
1459 1459 if (isfiltered == -1) {
1460 if (isfiltered) { 1460 PyErr_SetString(PyExc_TypeError,
1461 nothead[i] = 1; 1461 "unable to check filter");
1462 continue; 1462 goto bail;
1463 }
1464
1465 if (isfiltered) {
1466 nothead[i] = 1;
1467 continue;
1468 }
1463 } 1469 }
1464 1470
1465 if (index_get_parents(self, i, parents, (int)len - 1) < 0) 1471 if (index_get_parents(self, i, parents, (int)len - 1) < 0)
1466 goto bail; 1472 goto bail;
1467 for (j = 0; j < 2; j++) { 1473 for (j = 0; j < 2; j++) {