git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Thoughts about memory requirements in traversals [Was: Re: [RFC] Submodules in GIT]

From
JWJosef Weidendorfer <josef.weidendorfer@gmx.de>
Date
Dec 3, 2006, 02:07 UTC
Message-ID
<200612030307.26429.Josef.Weidendorfer@gmx.de>
In-Reply-To
<Pine.LNX.4.64.0612021252380.3476@woody.osdl.org>
On Saturday 02 December 2006 22:22, Linus Torvalds wrote:
Show 16 quoted lines
> So operations like "git-rev-list --objects" (or, these days, more commonly 
> anything that just does the equivalent of that internally using the 
> library interfaces - ie "git pack-objects" and friends) VERY FUNDAMENTALLY 
> have to hold on to the object flags for the whole lifetime of the whole 
> operation.
>
> [...]
> 
> So this really isn't a memory management issue. You could somewhat work 
> around it by adding a "caching layer" on top of git, and allow that 
> caching layer to modify their cache of old objects (so that they can 
> contain back-pointers), but for 99% of all users that would actually make 
> performance MUCH WORSE, and it would also be a serious problem for 
> coherency issues (one of the things that immutable objects cause is that 
> there are basically never any race conditions, while a "caching layer" 
> like this would have some serious issues about serialization).

Thinking about this... You have to make very sure to always update the caching layer containing the backlinks on every addition of a further object. You can do this because you always reached this new object by some other object, which exactly is the backpointer.

Now let us suppose we are able to do this. What does this give us?

Take a look at object traversal: We have to store the flag "already visited" for objects we could reach again in the traversal. But with the backlinks, we can see that most of the objects can only be reached via one path, and therefore, there is no need to store the flag, as it never will be queried in the further traversal. (Similar for objects with two paths: When you have visited the object two times, you can throw away the flag, as it is not queried any more).

Regarding the caching layer and object traversal, it would have been enough to only store "is this object reachable via more than 1 path?". For this, the "cache" could be the set of objects reachable with more than one path. And such a set stored in a file should be quite managable, and be quite small, relative to the size of the object database.

In fact, this "cache" can be created with a usual object traversal (which has the original memory requirement), but as long as we do not add objects to the database, further traversals would only need a fraction of memory.

When only adding a small number of objects, it should be easy to update the cache; while with big actions like fetching/pulling, we simply should remove the file with the backlink information.

> problem. In fact, O(n) is pretty damn good, especially since the constant 
> is pretty small (basically 28 bytes per object - and 20 of those bytes 
> are the SHA1 that you simply cannot avoid).

Again only some thoughts... Pack files are fully self-contained object stores, yes? So in the scope of a single pack file, the offset of this object is enough as object identification. If we could make sure that in any given algorithm touching objects, like commit traversal, we always have the offset available when we need to do an object lookup, then, it should be enough to store object flags only indexed by the offset of this object in the pack. The translation SHA1 -> offset can be done with the pack index. As you usually have multiple packs, a (pack number / offset) tuple should be enough as object ID.

Thinking even one step further: Would it make sense to define an encoding format for the content of commit and tree objects inside of packs, where the SHA1 is replaced by the offset of the object in this pack? As exactly the SHA1 is the least compressable thing, this could promise quite a benefit. AFAIK, we currently only use these offsets for referencing objects in delta chains.

More about the original topic of this thread (and off-topic to the new subject):

Show 11 quoted lines
> But it does mean that supermodules really should NOT be so seamless that 
> doing a "git clone" on a supermodule does one _large_ clone. Because it's 
> simply going to be better to:
> 
>  - when you clone the supermodule, track the commits you need on all 
>    submodules (this _may_ be a reason in itself for the "link" object, 
>    just so that you can traverse the supermodule object dependencies and 
>    know what subobject you are looking at even _without_ having to look at 
>    the path you got there from)
> 
>  - clone submodules one-by-one, using the list of objects you gathered.

Without submodule identities, we would have to clone path-by-path, as we can not distinguish different submodules apart from there location.

Previous: Linus TorvaldsNext: Linus Torvalds
Message 75 of 160 in “Re: [RFC] Submodules in GIT”
  1. Andy ParkinsNov 28, 2006
  2. Jakub NarebskiNov 28, 2006
  3. Andy ParkinsNov 28, 2006
  4. Shawn PearceNov 28, 2006
  5. Andy ParkinsNov 28, 2006
  6. Shawn PearceNov 28, 2006
  7. Jon LoeligerNov 28, 2006
  8. Martin WaitzNov 29, 2006
  9. sfNov 30, 2006
  10. Steven GrimmNov 28, 2006
  11. Shawn PearceNov 28, 2006
  12. Martin WaitzNov 29, 2006
  13. Andy ParkinsNov 29, 2006
  14. Andreas EricssonNov 30, 2006
  15. Andy ParkinsNov 30, 2006
  16. Martin WaitzNov 30, 2006
  17. Andreas EricssonNov 30, 2006
  18. sfDec 1, 2006
  19. Martin WaitzDec 1, 2006
  20. sfDec 1, 2006
  21. Martin WaitzDec 1, 2006
  22. Stephan FederDec 1, 2006
  23. Martin WaitzDec 1, 2006
  24. Stephan FederDec 1, 2006
  25. Martin WaitzDec 1, 2006
  26. Uwe Kleine-KoenigDec 5, 2006
  27. Andreas EricssonDec 5, 2006
  28. Jakub NarebskiDec 5, 2006
  29. Uwe Kleine-KoenigDec 5, 2006
  30. Andreas EricssonDec 5, 2006
  31. Sven VerdoolaegeDec 5, 2006
  32. Andy ParkinsDec 1, 2006
  33. Martin WaitzDec 1, 2006
  34. sfDec 1, 2006
  35. Martin WaitzDec 1, 2006
  36. sfDec 1, 2006
  37. Martin WaitzDec 1, 2006
  38. Andreas EricssonDec 1, 2006
  39. Martin WaitzDec 1, 2006
  40. Andreas EricssonDec 1, 2006
  41. Martin WaitzDec 1, 2006
  42. Andreas EricssonDec 1, 2006
  43. Linus TorvaldsDec 1, 2006
  44. sfDec 1, 2006
  45. Andreas EricssonDec 1, 2006
  46. Linus TorvaldsDec 1, 2006
  47. Martin WaitzDec 1, 2006
  48. Alan ChandlerDec 1, 2006
  49. Josef WeidendorferDec 1, 2006
  50. Martin WaitzDec 1, 2006
  51. Josef WeidendorferDec 1, 2006
  52. Martin WaitzDec 1, 2006
  53. Josef WeidendorferDec 1, 2006
  54. Martin WaitzDec 2, 2006
  55. Josef WeidendorferDec 3, 2006
  56. Martin WaitzDec 3, 2006
  57. Linus TorvaldsDec 1, 2006
  58. sfDec 1, 2006
  59. Josef WeidendorferDec 1, 2006
  60. Linus TorvaldsDec 1, 2006
  61. Josef WeidendorferDec 1, 2006
  62. Linus TorvaldsDec 2, 2006
  63. Andy ParkinsDec 2, 2006
  64. Josef WeidendorferDec 2, 2006
  65. Linus TorvaldsDec 2, 2006
  66. Martin WaitzDec 2, 2006
  67. Linus TorvaldsDec 2, 2006
  68. Martin WaitzDec 2, 2006
  69. Josef WeidendorferDec 3, 2006
  70. Martin WaitzDec 2, 2006
  71. Linus TorvaldsDec 2, 2006
  72. Martin WaitzDec 2, 2006
  73. Linus TorvaldsDec 2, 2006
  74. Linus TorvaldsDec 2, 2006
  75. Thoughts about memory requirements in traversals [Was: Re: [RFC] Submodules in GIT]Josef Weidendorfer, Dec 3, 2006
  76. Linus TorvaldsDec 3, 2006
  77. Shawn PearceDec 3, 2006
  78. Josef WeidendorferDec 3, 2006
  79. Jakub NarebskiDec 3, 2006
  80. Josef WeidendorferDec 3, 2006
  81. Martin WaitzDec 3, 2006
  82. sfDec 1, 2006
  83. Torgil SvenssonDec 2, 2006
  84. Linus TorvaldsDec 2, 2006
  85. Torgil SvenssonDec 3, 2006
  86. Linus TorvaldsDec 3, 2006
  87. Torgil SvenssonDec 4, 2006
  88. Linus TorvaldsDec 4, 2006
  89. Torgil SvenssonDec 4, 2006
  90. Andreas EricssonDec 5, 2006
  91. Jakub NarebskiDec 5, 2006
  92. Andreas EricssonDec 5, 2006
  93. Jakub NarebskiDec 5, 2006
  94. Andy ParkinsDec 3, 2006
  95. Daniel BarkalowDec 5, 2006
  96. sfDec 5, 2006
  97. R. Steve McKownDec 9, 2006
  98. Torgil SvenssonDec 10, 2006
  99. Torgil SvenssonDec 14, 2006
  100. Josef WeidendorferDec 14, 2006
  101. Torgil SvenssonDec 15, 2006
  102. Josef WeidendorferDec 15, 2006
  103. Torgil SvenssonDec 15, 2006
  104. Torgil SvenssonDec 16, 2006
  105. Torgil SvenssonDec 16, 2006
  106. Jakub NarebskiDec 16, 2006
  107. Torgil SvenssonDec 16, 2006
  108. Jakub NarebskiDec 16, 2006
  109. Junio C HamanoDec 16, 2006
  110. Torgil SvenssonDec 16, 2006
  111. Torgil SvenssonDec 16, 2006
  112. Jakub NarebskiDec 16, 2006
  113. Torgil SvenssonDec 17, 2006
  114. Linus TorvaldsDec 16, 2006
  115. Linus TorvaldsDec 16, 2006
  116. Torgil SvenssonDec 16, 2006
  117. Martin WaitzDec 2, 2006
  118. Josef WeidendorferDec 1, 2006
  119. Martin WaitzDec 1, 2006
  120. Linus TorvaldsDec 1, 2006
  121. Josef WeidendorferDec 2, 2006
  122. Linus TorvaldsDec 2, 2006
  123. Andy ParkinsDec 2, 2006
  124. Michael K. EdwardsDec 4, 2006
  125. Sam VilainDec 5, 2006
  126. Sven VerdoolaegeDec 3, 2006
  127. Linus TorvaldsDec 3, 2006
  128. Jakub NarebskiDec 3, 2006
  129. Josef WeidendorferDec 4, 2006
  130. sfDec 1, 2006
  131. Jon LoeligerDec 8, 2006
  132. Sven VerdoolaegeDec 8, 2006
  133. Andreas EricssonDec 12, 2006
  134. Martin WaitzDec 1, 2006
  135. Martin WaitzDec 1, 2006
  136. Andreas EricssonDec 1, 2006
  137. Martin WaitzDec 1, 2006
  138. Stephan FederDec 1, 2006
  139. Martin WaitzDec 1, 2006
  140. Stephan FederDec 1, 2006
  141. Martin WaitzDec 1, 2006
  142. Stephan FederDec 1, 2006
  143. Martin WaitzDec 1, 2006
  144. sfDec 1, 2006
  145. Martin WaitzDec 2, 2006
  146. Andy ParkinsDec 1, 2006
  147. Martin WaitzDec 1, 2006
  148. Andy ParkinsDec 1, 2006
  149. Martin WaitzDec 1, 2006
  150. Andy ParkinsDec 1, 2006
  151. Martin WaitzDec 1, 2006
  152. Andy ParkinsDec 2, 2006
  153. Josef WeidendorferDec 2, 2006
  154. Martin WaitzDec 2, 2006
  155. Josef WeidendorferDec 3, 2006
  156. Martin WaitzDec 2, 2006
  157. Jakub NarebskiDec 2, 2006
  158. Jakub NarebskiDec 2, 2006
  159. Jakub NarebskiDec 2, 2006
  160. Andy ParkinsDec 3, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.