optimise adjustTree when adding many TreeItems
authorJoey Hess <joeyh@joeyh.name>
Wed, 3 Jan 2024 19:07:49 +0000 (15:07 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 3 Jan 2024 19:07:49 +0000 (15:07 -0400)
commit2c86651180d5c8648b8244be894c26bc98a6c334
tree1db9d017eb73512bb0309b4e7e3e77919c6514c2
parenta6a67f79e74989c9389ebc0aa664742187eecb27
optimise adjustTree when adding many TreeItems

The old code traversed the list of addtreeitems once per subdirectory in
the tree, so could get quite slow. Converting to Map lookups sped it up
significantly.

In my test case, git-annex import used to take about 2 minutes, when
calling adjustTree to add back excluded files to the imported tree. This
dropped it down to 6 seconds. Of which 4 seconds are the actual
enumeration of the contents of the remote, so really only 2 seconds for
this.

The path prefix map is a bit suboptimal memory-wise, since items get
stored in the map once per subdirectory on the path to the item. It
would perhaps be better to use a tree data structure.

Also it's suboptimal memory-wise that it builds two maps, as well
as retaining a reference to addtreeitems. I could not see a way around
that though.

Sponsored-by: Luke T. Shumaker on Patreon
CHANGELOG
Git/Tree.hs
doc/todo/speed_up_import_tree_with_many_excluded_files.mdwn