{"thread":{"id":"3861","subject":"Use less memory in \"git log\"","startedAt":"2006-04-13T17:01:02Z","lastAt":"2006-04-13T17:01:02Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"18613","messageId":"Pine.LNX.4.64.0604130950130.14565@g5.osdl.org","threadId":"3861","inReplyTo":null,"subject":"Use less memory in \"git log\"","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-04-13T17:01:02Z","receivedAt":"2006-04-13T17:01:02Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nThis trivially avoids keeping the commit message data around after we \ndon't need it any more, avoiding a continually growing \"git log\" memory \nfootprint.\n\nIt's not a huge deal, but it's somewhat noticeable. For the current kernel \ntree, doing a full \"git log\" I got\n\n - before: /usr/bin/time git log > /dev/null \n\t0.81user 0.02system 0:00.84elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k\n\t0inputs+0outputs (0major+8851minor)pagefaults 0swaps\n\n - after: /usr/bin/time git log > /dev/null \n\t0.79user 0.03system 0:00.83elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k\n\t0inputs+0outputs (0major+5039minor)pagefaults 0swaps\n\nie the touched pages dropped from 8851 to 5039. For the historic kernel \narchive, the numbers are 18357->11037 minor page faults.\n\nWe could/should in theory free the commits themselves, but that's really a \nlot harder, since during revision traversal we may hit the same commit \ntwice through different children having it as a parent, even after we've \nshown it once (when that happens, we'll silently ignore it next time, but \nwe still need the \"struct commit\" to know).\n\nAnd as the commit message data is clearly the biggest part of the commit, \nthis is the really easy 60% solution.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\ndiff --git a/git.c b/git.c\nindex d6f17db..78ed403 100644\n--- a/git.c\n+++ b/git.c\n@@ -391,6 +391,8 @@ static int cmd_log(int argc, const char \n \t\tif (do_diff)\n \t\t\tlog_tree_commit(&opt, commit);\n \t\tshown = 1;\n+\t\tfree(commit->buffer);\n+\t\tcommit->buffer = NULL;\n \t}\n \tfree(buf);\n \treturn 0;\n"}]}