Reroute range removal pruning through diverged path swaps

I think this was just an oversight when merging/unmerging pruning
operations. Lazily finding alts (eagerly swapping) seems to result in
better trees based on some napkin sketches.

For example, consider this remove, with lazy alts (eager swaps):

         .-------o-------.
     .---o---.       .---o---.            .-----------------o
   .-o-.   .-o-.   .-o-.   .-o-.        .-o-.   .-----------o
  .o. .o. .o. .o. .o. .o. .o. .o.      .o. .o. .o. .--------o--------.
  a b c d e f g h i j k l m n o p  =>  a b c d e f g                 p
               '-------+-------'
                     remove                        h=3

And with eager alts (lazy swaps):

         .-------o-------.                .-----------------o
     .---o---.       .---o---.            |                 o--------.
   .-o-.   .-o-.   .-o-.   .-o-.        .-o-.   .--.--------o        |
  .o. .o. .o. .o. .o. .o. .o. .o.      .o. .o. .o. |                 |
  a b c d e f g h i j k l m n o p  =>  a b c d e f g                 p
               '-------+-------'
                     remove                        h=4

This isn't really rigorous, but without more evidence lazy alts (eager
swaps) seem the best option for now.

Note that we do _not_ eagerly swap when pruning yellow alts. The two
other continue statements in the appendattr loop, one for pruning yellow
alts and one for splitting yellow alts, are bookkeeping operations that
don't map to real alt visits. We should pretend these alts don't exist
when looking at the tree layout.

With diverged recoloring, we can't actually hit the yellow-split case,
but we can hit the yellow pruning case since it only relies on
unreachability.

Code cost, uh, I don't really know why this saved code, it's probably
just compiler noise:

           code          stack
  before: 33992           2880
  after:  33976 (+0.0%)   2880 (+0.0%)
This commit is contained in:
Christopher Haster
2024-03-06 15:09:40 -06:00
parent 47416c1115
commit f62ae0e8fd
+2 -1
View File
@@ -2858,7 +2858,7 @@ static int lfsr_rbyd_appendattr(lfs_t *lfs, lfsr_rbyd_t *rbyd,
graft = branch;
branch = branch_;
continue;
goto next;
}
}
@@ -3036,6 +3036,7 @@ static int lfsr_rbyd_appendattr(lfs_t *lfs, lfsr_rbyd_t *rbyd,
}
}
next:;
// switch to the other path if we have diverged
if (lfsr_tag_hasdiverged(tag_)) {
lfs_swap16(&tag_, &other_tag_);