@matheusbsbs / matheus-bagliano / commits / f7c22cc68c
Fork 0

always start looking up objects in the last used pack first

Jon Smirl said: | Once an object reference hits a pack file it is very likely that | following references will hit the same pack file. So first place to | look for an object is the same place the previous object was found. This is indeed a good heuristic so here it is. The search always start with the pack where the last object lookup succeeded. If the wanted object is not available there then the search continues with the normal pack ordering. To test this I split the Linux repository into 66 packs and performed a "time git-rev-list --objects --all > /dev/null". Best results are as follows: Pack Sort w/o this patch w/ this patch ------------------------------------------------------------- recent objects last 26.4s 20.9s recent objects first 24.9s 18.4s This shows that the pack order based on object age has some influence, but that the last-used-pack heuristic is even more significant in reducing object lookup. Signed-off-by: Nicolas Pitre <nico@cam.org> --- Note: the --max-pack-size to git-repack currently produces packs with old objects after those containing recent objects. The pack sort based on filesystem timestamp is therefore backward for those. This needs to be fixed of course, but at least it made me think about this variable for the test. Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed May 30, 2007 at 22:48 UTC f7c22cc68ccba0cb5bbd43177507795c48afb1f5
1 file changed +18 -4
sha1_file.c
+18 -4
@@ -1654,20 +1654,25 @@ static int matches_pack_name(struct packed_git *p, const char *ig)
1654
1655 static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
1656 {
1657 + static struct packed_git *last_found = (void *)1;
1658 struct packed_git *p;
1659 off_t offset;
1660
1661 prepare_packed_git();
1662 + if (!packed_git)
1663 + return 0;
1664 + p = (last_found == (void *)1) ? packed_git : last_found;
1665
1662 - for (p = packed_git; p; p = p->next) {
1666 + do {
1667 if (ignore_packed) {
1668 const char **ig;
1669 for (ig = ignore_packed; *ig; ig++)
1670 if (!matches_pack_name(p, *ig))
1671 break;
1672 if (*ig)
1669 - continue;
1673 + goto next;
1674 }
1675 +
1676 offset = find_pack_entry_one(sha1, p);
1677 if (offset) {
1678 /*
@@ -1680,14 +1685,23 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, cons
1685 */
1686 if (p->pack_fd == -1 && open_packed_git(p)) {
1687 error("packfile %s cannot be accessed", p->pack_name);
1683 - continue;
1688 + goto next;
1689 }
1690 e->offset = offset;
1691 e->p = p;
1692 hashcpy(e->sha1, sha1);
1693 + last_found = p;
1694 return 1;
1695 }
1690 - }
1696 +
1697 + next:
1698 + if (p == last_found)
1699 + p = packed_git;
1700 + else
1701 + p = p->next;
1702 + if (p == last_found)
1703 + p = p->next;
1704 + } while (p);
1705 return 0;
1706 }
1707