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

Re: [GSoC] Designing a faster index format

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Apr 5, 2012, 10:43 UTC
Message-ID
<4F7D7759.6020603@alum.mit.edu>
In-Reply-To
<C15BAB9A-EAFA-4EA4-85B2-0E0C5FF473E9@gmail.com>
On 04/03/2012 09:07 PM, Thomas Gummerer wrote:
Show 24 quoted lines
> On Apr 3, 2012, at 10:51 AM, Michael Haggerty wrote:
>> On 04/02/2012 11:02 PM, Thomas Gummerer wrote:
>>> - Append-only data structure
>>> [...]
>>> To make sure the index isn't corrupted, without calculating the sha1 hash for
>>> the whole index file every time something is changed, the hash is always
>>> calculated for the whole index when merging, but when only a single entry is 
>>> changed the sha-1 hash is only calculated for the last change. This will 
>>> increase the cost for reading the index to log(n) + k * log(k) where n is the 
>>> number of entries in the sorted part of the index and k is the number of entries
>>> in the unsorted part of the index, which will have to be merged with the rest 
>>> of the index.
>>
>> I don't understand this analysis of the reading time.  I suppose you are
>> assuming that you want to read the status of a single file.  But in that
>> case, it is enough to find the entry in the old index (O(log(n))
>> assuming some sort of tree structure) plus do a linear scan through the
>> unsorted entries (i.e., O(k), not O(k log(k))).
> 
> The current way git operates it always reads the whole index, making it necessary
> to merge the unsorted entries with the sorted part. Thinking about it it would even
> be O(k log(n)), because the appended part is unsorted.
> O(log(n)) + O(k) would be the complexity for loading only a single entry from the
> index.

I was confused because in your original mail you seemed to claim that reading the whole sorted part of the index scales like O(log(n)), where it certainly scales at least like O(n).

To read the whole index if using an append-only data structure, I would do the following:

1. Read the file header to find where the addenda begin: one seek plus O(1).
2. Read the addenda in order (I assume each addendum to be sorted on
disk), and merge-sort the addenda together, discarding the earlier of
any duplicates: one seek plus O(k) I/O plus O(k log k) computation (this
is the worst case, if each addendum contains a single file).
3. Read the sorted part of the file in order, while merging it together
with the combined addenda: one seek plus O(n) I/O plus O(n + k) computation.
Total: 3 seeks plus O(n+k) I/O plus O(n + k log(k)) computation.

Whereas for a B-tree, it is hard to estimate the complexity because you have provided very little detail about how you want to lay the data structure out on disk. But presumably the number of seeks will be significantly larger. And if you are not careful, the number of seeks will approach the number of nodes in the index O(n) or perhaps the number of added nodes (not files!) which could go something like O(k log(k)).

Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Previous: Shawn PearceNext: Nguyen Thai Ngoc Duy
Message 33 of 36 in “[GSoC] Designing a faster index format”
  1. Thomas GummererMar 20, 2012
  2. Nguyen Thai Ngoc DuyMar 21, 2012
  3. Thomas GummererMar 21, 2012
  4. Nguyen Thai Ngoc DuyMar 21, 2012
  5. Thomas RastMar 21, 2012
  6. Thomas GummererMar 21, 2012
  7. Thomas RastMar 21, 2012
  8. Thomas GummererMar 22, 2012
  9. Thomas RastMar 23, 2012
  10. Thomas GummererMar 25, 2012
  11. Thomas GummererMar 26, 2012
  12. Junio C HamanoMar 26, 2012
  13. Thomas GummererMar 27, 2012
  14. Thomas RastMar 27, 2012
  15. Thomas GummererMar 29, 2012
  16. Junio C HamanoMar 29, 2012
  17. Nguyen Thai Ngoc DuyMar 30, 2012
  18. Thomas GummererApr 2, 2012
  19. Michael HaggertyApr 3, 2012
  20. Nguyen Thai Ngoc DuyApr 3, 2012
  21. Thomas GummererApr 3, 2012
  22. david@lang.hmApr 3, 2012
  23. Thomas GummererApr 4, 2012
  24. Noel GrandinApr 5, 2012
  25. Thomas RastApr 5, 2012
  26. Shawn PearceApr 6, 2012
  27. Nguyen Thai Ngoc DuyApr 6, 2012
  28. Thomas RastApr 6, 2012
  29. Nguyen Thai Ngoc DuyApr 6, 2012
  30. Shawn PearceApr 6, 2012
  31. Nguyen Thai Ngoc DuyApr 6, 2012
  32. Shawn PearceApr 6, 2012
  33. Michael HaggertyApr 5, 2012
  34. Nguyen Thai Ngoc DuyMar 21, 2012
  35. Nguyen Thai Ngoc DuyApr 19, 2012
  36. Jeff KingApr 20, 2012

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.