[PATCH] Avoid wasting memory in git-rev-list

As pointed out on the list, git-rev-list can use a lot of memory.

One low-hanging fruit is to free the commit buffer for commits that we
parse. By default, parse_commit() will save away the buffer, since a lot
of cases do want it, and re-reading it continually would be unnecessary.
However, in many cases the buffer isn't actually necessary and saving it
just wastes memory.

We could just free the buffer ourselves, but especially in git-rev-list,
we actually end up using the helper functions that automatically add
parent commits to the commit lists, so we don't actually control the
commit parsing directly.

Instead, just make this behaviour of "parse_commit()" a global flag.
Maybe this is a bit tasteless, but it's very simple, and it makes a
noticable difference in memory usage.

Before the change:

	[torvalds@g5 linux]$ /usr/bin/time git-rev-list v2.6.12..HEAD > /dev/null
	0.26user 0.02system 0:00.28elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
	0inputs+0outputs (0major+3714minor)pagefaults 0swaps

after the change:

	[torvalds@g5 linux]$ /usr/bin/time git-rev-list v2.6.12..HEAD > /dev/null
	0.26user 0.00system 0:00.27elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
	0inputs+0outputs (0major+2433minor)pagefaults 0swaps

note how the minor faults have decreased from 3714 pages to 2433 pages.
That's all due to the fewer anonymous pages allocated to hold the comment
buffers and their metadata.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
3 files changed
tree: dfed215bfc5ca6f409fb780465757ab70d64c30f
  1. debian/
  2. Documentation/
  3. mozilla-sha1/
  4. ppc/
  5. t/
  6. templates/
  7. .gitignore
  8. apply.c
  9. blob.c
  10. blob.h
  11. cache.h
  12. cat-file.c
  13. checkout-index.c
  14. clone-pack.c
  15. cmd-rename.sh
  16. commit-tree.c
  17. commit.c
  18. commit.h
  19. connect.c
  20. convert-objects.c
  21. COPYING
  22. count-delta.c
  23. count-delta.h
  24. csum-file.c
  25. csum-file.h
  26. daemon.c
  27. date.c
  28. delta.h
  29. diff-delta.c
  30. diff-files.c
  31. diff-helper.c
  32. diff-index.c
  33. diff-stages.c
  34. diff-tree.c
  35. diff.c
  36. diff.h
  37. diffcore-break.c
  38. diffcore-order.c
  39. diffcore-pathspec.c
  40. diffcore-pickaxe.c
  41. diffcore-rename.c
  42. diffcore.h
  43. entry.c
  44. epoch.c
  45. epoch.h
  46. export.c
  47. fetch-pack.c
  48. fetch.c
  49. fetch.h
  50. fsck-objects.c
  51. get-tar-commit-id.c
  52. git-add.sh
  53. git-applymbox.sh
  54. git-applypatch.sh
  55. git-archimport.perl
  56. git-bisect.sh
  57. git-branch.sh
  58. git-checkout.sh
  59. git-cherry.sh
  60. git-clone.sh
  61. git-commit.sh
  62. git-core.spec.in
  63. git-count-objects.sh
  64. git-cvsimport.perl
  65. git-diff.sh
  66. git-external-diff-script
  67. git-fetch.sh
  68. git-format-patch.sh
  69. git-grep.sh
  70. git-log.sh
  71. git-ls-remote.sh
  72. git-merge-octopus.sh
  73. git-merge-one-file.sh
  74. git-merge-recursive.py
  75. git-merge-resolve.sh
  76. git-merge-stupid.sh
  77. git-merge.sh
  78. git-octopus.sh
  79. git-parse-remote.sh
  80. git-prune.sh
  81. git-pull.sh
  82. git-push.sh
  83. git-rebase.sh
  84. git-relink.perl
  85. git-rename.perl
  86. git-repack.sh
  87. git-request-pull.sh
  88. git-reset.sh
  89. git-resolve.sh
  90. git-revert.sh
  91. git-send-email.perl
  92. git-sh-setup.sh
  93. git-shortlog.perl
  94. git-status.sh
  95. git-tag.sh
  96. git-verify-tag.sh
  97. git-whatchanged.sh
  98. git.sh
  99. gitk
  100. gitMergeCommon.py
  101. hash-object.c
  102. http-fetch.c
  103. ident.c
  104. index.c
  105. init-db.c
  106. INSTALL
  107. local-fetch.c
  108. ls-files.c
  109. ls-tree.c
  110. mailinfo.c
  111. mailsplit.c
  112. Makefile
  113. merge-base.c
  114. merge-index.c
  115. mktag.c
  116. object.c
  117. object.h
  118. pack-check.c
  119. pack-objects.c
  120. pack.h
  121. patch-delta.c
  122. patch-id.c
  123. path.c
  124. peek-remote.c
  125. pkt-line.c
  126. pkt-line.h
  127. prune-packed.c
  128. quote.c
  129. quote.h
  130. read-cache.c
  131. read-tree.c
  132. README
  133. receive-pack.c
  134. refs.c
  135. refs.h
  136. rev-list.c
  137. rev-parse.c
  138. rev-tree.c
  139. rsh.c
  140. rsh.h
  141. run-command.c
  142. run-command.h
  143. send-pack.c
  144. server-info.c
  145. setup.c
  146. sha1_file.c
  147. sha1_name.c
  148. show-branch.c
  149. show-index.c
  150. ssh-fetch.c
  151. ssh-pull.c
  152. ssh-push.c
  153. ssh-upload.c
  154. strbuf.c
  155. strbuf.h
  156. stripspace.c
  157. tag.c
  158. tag.h
  159. tar-tree.c
  160. test-date.c
  161. test-delta.c
  162. tree.c
  163. tree.h
  164. unpack-file.c
  165. unpack-objects.c
  166. update-index.c
  167. update-server-info.c
  168. upload-pack.c
  169. usage.c
  170. var.c
  171. verify-pack.c
  172. write-tree.c