Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BTreeMap/BTreeSet: implement drain_filter #68770

Merged
merged 2 commits into from
Apr 1, 2020

Conversation

ssomers
Copy link
Contributor

@ssomers ssomers commented Feb 2, 2020

Provide an implementation of drain_filter for BTreeMap and BTreeSet. Should be optimal when the predicate picks only elements in leaf nodes with at least MIN_LEN remaining elements, which is a common case, at least when draining only a fraction of the map/set, and also when the predicate picks elements stored in internal nodes where the right subtree can easily let go of a replacement element.

The first commit adds benchmarks with an external, naive implementation. to compare how much this claimed optimality-in-some-cases is actually worth.

@rust-highfive
Copy link
Collaborator

r? @withoutboats

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 2, 2020
@ssomers
Copy link
Contributor Author

ssomers commented Feb 2, 2020

Performance numbers (Windows x64):

  • compared to btree::set::clone_100:
    • 0.9 µs/iter for similar behaviour btree::set::clone_100_and_remove_half
    • 2.05 µs/iter for naive implementation btree::set::clone_100_and_drain_half, 1st commit
    • 1.7 µs/iter for actual implementation btree::set::clone_100_and_drain_half, 2nd commit
  • btree::set::clone_10k_and_drain_half over btree::set::clone_10k:
    • 262 µs/iter for similar behaviour btree::set::clone_10k_and_remove_half
    • 340 µs/iter for naive implementation btree::set::clone_10k_and_drain_half, 1st commit
    • 210 µs/iter for actual implementation btree::set::clone_10k_and_drain_half, 2nd commit

The benchmarks of remove suggest a 5% impact, but it's too close to call above the usual noise. It's easy to duplicate the remove_kv implementation to avoid that, but then we have even more code.

>cargo benchcmp old5.txt new4.txt
 name                                           old5.txt ns/iter  new4.txt ns/iter  diff ns/iter   diff %  speedup
 btree::map::find_rand_100                      18                17                          -1   -5.56%   x 1.06
 btree::map::find_rand_10_000                   58                59                           1    1.72%   x 0.98
 btree::map::find_seq_100                       18                19                           1    5.56%   x 0.95
 btree::map::find_seq_10_000                    40                39                          -1   -2.50%   x 1.03
 btree::map::first_and_last_0                   34                40                           6   17.65%   x 0.85
 btree::map::first_and_last_100                 38                46                           8   21.05%   x 0.83
 btree::map::first_and_last_10k                 67                68                           1    1.49%   x 0.99
 btree::map::insert_rand_100                    34                40                           6   17.65%   x 0.85
 btree::map::insert_rand_10_000                 34                40                           6   17.65%   x 0.85
 btree::map::insert_seq_100                     46                50                           4    8.70%   x 0.92
 btree::map::insert_seq_10_000                  95                101                          6    6.32%   x 0.94
 btree::map::iter_1000                          8,825             8,756                      -69   -0.78%   x 1.01
 btree::map::iter_100000                        1,035,180         1,055,780               20,600    1.99%   x 0.98
 btree::map::iter_20                            173               166                         -7   -4.05%   x 1.04
 btree::map::iter_mut_1000                      8,552             8,485                      -67   -0.78%   x 1.01
 btree::map::iter_mut_100000                    1,016,760         1,024,030                7,270    0.72%   x 0.99
 btree::map::iter_mut_20                        165               165                          0    0.00%   x 1.00
 btree::set::clone_100                          1,788             1,857                       69    3.86%   x 0.96
 btree::set::clone_100_and_clear                1,788             1,824                       36    2.01%   x 0.98
 btree::set::clone_100_and_drain_half           3,847             3,533                     -314   -8.16%   x 1.09
 btree::set::clone_100_and_into_iter            1,876             1,947                       71    3.78%   x 0.96
 btree::set::clone_100_and_pop_all              2,451             2,726                      275   11.22%   x 0.90
 btree::set::clone_100_and_remove_all           4,375             4,659                      284    6.49%   x 0.94
 btree::set::clone_100_and_remove_half          2,688             2,677                      -11   -0.41%   x 1.00
 btree::set::clone_10k                          186,619           189,187                  2,568    1.38%   x 0.99
 btree::set::clone_10k_and_clear                191,357           188,922                 -2,435   -1.27%   x 1.01
 btree::set::clone_10k_and_drain_half           526,600           399,395               -127,205  -24.16%   x 1.32
 btree::set::clone_10k_and_into_iter            197,565           197,822                    257    0.13%   x 1.00
 btree::set::clone_10k_and_pop_all              253,590           265,890                 12,300    4.85%   x 0.95
 btree::set::clone_10k_and_remove_all           511,660           562,420                 50,760    9.92%   x 0.91
 btree::set::clone_10k_and_remove_half          438,330           451,475                 13,145    3.00%   x 0.97
 btree::set::difference_random_100_vs_100       1,754             1,778                       24    1.37%   x 0.99
 btree::set::difference_random_100_vs_10k       3,105             2,853                     -252   -8.12%   x 1.09
 btree::set::difference_random_10k_vs_100       109,861           108,462                 -1,399   -1.27%   x 1.01
 btree::set::difference_random_10k_vs_10k       241,345           240,842                   -503   -0.21%   x 1.00
 btree::set::difference_staggered_100_vs_100    1,738             1,780                       42    2.42%   x 0.98
 btree::set::difference_staggered_100_vs_10k    2,743             2,802                       59    2.15%   x 0.98
 btree::set::difference_staggered_10k_vs_10k    175,880           171,836                 -4,044   -2.30%   x 1.02
 btree::set::intersection_100_neg_vs_100_pos    27                28                           1    3.70%   x 0.96
 btree::set::intersection_100_neg_vs_10k_pos    32                31                          -1   -3.12%   x 1.03
 btree::set::intersection_100_pos_vs_100_neg    27                28                           1    3.70%   x 0.96
 btree::set::intersection_100_pos_vs_10k_neg    32                31                          -1   -3.12%   x 1.03
 btree::set::intersection_10k_neg_vs_100_pos    30                30                           0    0.00%   x 1.00
 btree::set::intersection_10k_neg_vs_10k_pos    32                33                           1    3.12%   x 0.97
 btree::set::intersection_10k_pos_vs_100_neg    30                30                           0    0.00%   x 1.00
 btree::set::intersection_10k_pos_vs_10k_neg    32                33                           1    3.12%   x 0.97
 btree::set::intersection_random_100_vs_100     1,540             1,526                      -14   -0.91%   x 1.01
 btree::set::intersection_random_100_vs_10k     2,778             2,722                      -56   -2.02%   x 1.02
 btree::set::intersection_random_10k_vs_100     2,622             2,760                      138    5.26%   x 0.95
 btree::set::intersection_random_10k_vs_10k     220,770           217,033                 -3,737   -1.69%   x 1.02
 btree::set::intersection_staggered_100_vs_100  2,003             1,409                     -594  -29.66%   x 1.42
 btree::set::intersection_staggered_100_vs_10k  2,612             2,492                     -120   -4.59%   x 1.05
 btree::set::intersection_staggered_10k_vs_10k  199,521           141,172                -58,349  -29.24%   x 1.41
 btree::set::is_subset_100_vs_100               1,315             1,348                       33    2.51%   x 0.98
 btree::set::is_subset_100_vs_10k               1,715             1,806                       91    5.31%   x 0.95
 btree::set::is_subset_10k_vs_100               2                 2                            0    0.00%   x 1.00
 btree::set::is_subset_10k_vs_10k               133,031           136,565                  3,534    2.66%   x 0.97

@ssomers ssomers changed the title Btree drain filter BTreeMap/BTreeSet: implement drain_filter Feb 2, 2020
@ssomers ssomers requested a review from cuviper February 2, 2020 13:06
@cuviper
Copy link
Member

cuviper commented Feb 3, 2020

 btree::set::intersection_random_100_vs_100     1,540             1,526                      -14   -0.91%   x 1.01
 btree::set::intersection_random_100_vs_10k     2,778             2,722                      -56   -2.02%   x 1.02
 btree::set::intersection_random_10k_vs_100     2,622             2,760                      138    5.26%   x 0.95
 btree::set::intersection_random_10k_vs_10k     220,770           217,033                 -3,737   -1.69%   x 1.02
 btree::set::intersection_staggered_100_vs_100  2,003             1,409                     -594  -29.66%   x 1.42
 btree::set::intersection_staggered_100_vs_10k  2,612             2,492                     -120   -4.59%   x 1.05
 btree::set::intersection_staggered_10k_vs_10k  199,521           141,172                -58,349  -29.24%   x 1.41

These large changes have nothing to do with your code, do they? I fear we're too much at the mercy of compilation changes here, probably with the way codegen is splitting things as you add more code. Could you try with codegen-units-std = 1 in your config.toml?

src/liballoc/collections/btree/map.rs Outdated Show resolved Hide resolved
src/liballoc/collections/btree/map.rs Show resolved Hide resolved
src/liballoc/collections/btree/map.rs Outdated Show resolved Hide resolved
src/liballoc/collections/btree/map.rs Show resolved Hide resolved
src/liballoc/collections/btree/map.rs Show resolved Hide resolved
src/liballoc/collections/btree/set.rs Outdated Show resolved Hide resolved
src/liballoc/collections/btree/set.rs Outdated Show resolved Hide resolved
src/liballoc/collections/btree/set.rs Show resolved Hide resolved
src/liballoc/collections/btree/map.rs Outdated Show resolved Hide resolved
src/liballoc/collections/btree/map.rs Outdated Show resolved Hide resolved
@ssomers
Copy link
Contributor Author

ssomers commented Feb 4, 2020

These large changes have nothing to do with your code, do they?

No, intersection is basically immutable iteration, which has its own functions in the tree navigation code, whose implementation or inlining does not depend on adding a function for mutable iteration next to it. Unless it does.

I hadn't actually noticed the large ones this time, the ones taking more than tens of ns. Differences of 25% in a few tests are common but these are unusual in my experience,. Yet I had a 250%, equally unrelated change recently, rebuilt both versions with the same result (assuming and observing that x.py does seem to notice the changed files, but without cleaning the build directory). Then rebuilt again the next day and the difference had vanished.

I rebuilt these with clearning the build directory, and the result is more reasonable:

>cargo benchcmp old2.txt new4.txt
 name                                           old2.txt ns/iter  new4.txt ns/iter  diff ns/iter   diff %  speedup
 btree::map::find_rand_100                      18                18                           0    0.00%   x 1.00
 btree::map::find_rand_10_000                   57                57                           0    0.00%   x 1.00
 btree::map::find_seq_100                       20                18                          -2  -10.00%   x 1.11
 btree::map::find_seq_10_000                    40                40                           0    0.00%   x 1.00
 btree::map::first_and_last_0                   34                39                           5   14.71%   x 0.87
 btree::map::first_and_last_100                 38                46                           8   21.05%   x 0.83
 btree::map::first_and_last_10k                 67                68                           1    1.49%   x 0.99
 btree::map::insert_rand_100                    34                41                           7   20.59%   x 0.83
 btree::map::insert_rand_10_000                 34                41                           7   20.59%   x 0.83
 btree::map::insert_seq_100                     46                49                           3    6.52%   x 0.94
 btree::map::insert_seq_10_000                  95                97                           2    2.11%   x 0.98
 btree::map::iter_1000                          8,785             8,753                      -32   -0.36%   x 1.00
 btree::map::iter_100000                        1,049,370         1,046,830               -2,540   -0.24%   x 1.00
 btree::map::iter_20                            165               166                          1    0.61%   x 0.99
 btree::map::iter_mut_1000                      8,408             8,753                      345    4.10%   x 0.96
 btree::map::iter_mut_100000                    1,021,130         1,042,800               21,670    2.12%   x 0.98
 btree::map::iter_mut_20                        162               171                          9    5.56%   x 0.95
 btree::set::clone_100                          1,817             1,807                      -10   -0.55%   x 1.01
 btree::set::clone_100_and_clear                1,776             1,834                       58    3.27%   x 0.97
 btree::set::clone_100_and_drain_half           3,849             3,493                     -356   -9.25%   x 1.10
 btree::set::clone_100_and_into_iter            1,882             1,880                       -2   -0.11%   x 1.00
 btree::set::clone_100_and_pop_all              2,343             2,763                      420   17.93%   x 0.85
 btree::set::clone_100_and_remove_all           4,463             4,558                       95    2.13%   x 0.98
 btree::set::clone_100_and_remove_half          2,605             2,713                      108    4.15%   x 0.96
 btree::set::clone_10k                          190,520           190,571                     51    0.03%   x 1.00
 btree::set::clone_10k_and_clear                186,420           192,822                  6,402    3.43%   x 0.97
 btree::set::clone_10k_and_drain_half           537,490           388,947               -148,543  -27.64%   x 1.38
 btree::set::clone_10k_and_into_iter            195,362           201,155                  5,793    2.97%   x 0.97
 btree::set::clone_10k_and_pop_all              247,086           265,843                 18,757    7.59%   x 0.93
 btree::set::clone_10k_and_remove_all           501,280           561,470                 60,190   12.01%   x 0.89
 btree::set::clone_10k_and_remove_half          436,650           450,770                 14,120    3.23%   x 0.97
 btree::set::difference_random_100_vs_100       1,753             1,786                       33    1.88%   x 0.98
 btree::set::difference_random_100_vs_10k       3,001             3,045                       44    1.47%   x 0.99
 btree::set::difference_random_10k_vs_100       108,445           107,753                   -692   -0.64%   x 1.01
 btree::set::difference_random_10k_vs_10k       237,000           242,985                  5,985    2.53%   x 0.98
 btree::set::difference_staggered_100_vs_100    1,740             1,738                       -2   -0.11%   x 1.00
 btree::set::difference_staggered_100_vs_10k    2,776             2,764                      -12   -0.43%   x 1.00
 btree::set::difference_staggered_10k_vs_10k    172,718           172,876                    158    0.09%   x 1.00
 btree::set::intersection_100_neg_vs_100_pos    27                27                           0    0.00%   x 1.00
 btree::set::intersection_100_neg_vs_10k_pos    32                31                          -1   -3.12%   x 1.03
 btree::set::intersection_100_pos_vs_100_neg    26                27                           1    3.85%   x 0.96
 btree::set::intersection_100_pos_vs_10k_neg    31                31                           0    0.00%   x 1.00
 btree::set::intersection_10k_neg_vs_100_pos    30                30                           0    0.00%   x 1.00
 btree::set::intersection_10k_neg_vs_10k_pos    32                33                           1    3.12%   x 0.97
 btree::set::intersection_10k_pos_vs_100_neg    30                30                           0    0.00%   x 1.00
 btree::set::intersection_10k_pos_vs_10k_neg    33                33                           0    0.00%   x 1.00
 btree::set::intersection_random_100_vs_100     1,562             1,546                      -16   -1.02%   x 1.01
 btree::set::intersection_random_100_vs_10k     2,707             2,673                      -34   -1.26%   x 1.01
 btree::set::intersection_random_10k_vs_100     2,607             2,650                       43    1.65%   x 0.98
 btree::set::intersection_random_10k_vs_10k     223,752           216,952                 -6,800   -3.04%   x 1.03
 btree::set::intersection_staggered_100_vs_100  1,404             1,404                        0    0.00%   x 1.00
 btree::set::intersection_staggered_100_vs_10k  2,523             2,452                      -71   -2.81%   x 1.03
 btree::set::intersection_staggered_10k_vs_10k  140,725           140,665                    -60   -0.04%   x 1.00
 btree::set::is_subset_100_vs_100               1,347             1,315                      -32   -2.38%   x 1.02
 btree::set::is_subset_100_vs_10k               1,690             1,686                       -4   -0.24%   x 1.00
 btree::set::is_subset_10k_vs_100               2                 2                            0    0.00%   x 1.00
 btree::set::is_subset_10k_vs_10k               133,132           132,897                   -235   -0.18%   x 1.00
WARNING: benchmarks in new but not in old: btree::set::clone_100_and_drain_all, btree::set::clone_10k_and_drain_all

or focusing on the changes:

>cargo benchcmp old2.txt new4.txt --threshold 10
 name                                  old2.txt ns/iter  new4.txt ns/iter  diff ns/iter   diff %  speedup
 btree::map::find_seq_100              20                18                          -2  -10.00%   x 1.11
 btree::map::first_and_last_0          34                39                           5   14.71%   x 0.87
 btree::map::first_and_last_100        38                46                           8   21.05%   x 0.83
 btree::map::insert_rand_100           34                41                           7   20.59%   x 0.83
 btree::map::insert_rand_10_000        34                41                           7   20.59%   x 0.83
 btree::set::clone_100_and_pop_all     2,343             2,763                      420   17.93%   x 0.85
 btree::set::clone_10k_and_drain_half  537,490           388,947               -148,543  -27.64%   x 1.38
 btree::set::clone_10k_and_remove_all  501,280           561,470                 60,190   12.01%   x 0.89

PS codegen-units-std = 1 doesn't seem to make a difference. Same variation across different runs of the same build, e.g.:

name                                         old1-4.txt ns/iter  old1-5.txt ns/iter  diff ns/iter   diff %  speedup
 btree::map::find_rand_100                    19                  18                            -1   -5.26%   x 1.06
 btree::map::find_seq_100                     19                  18                            -1   -5.26%   x 1.06
 btree::map::insert_seq_10_000                107                 101                           -6   -5.61%   x 1.06
 btree::set::difference_random_100_vs_10k     3,088               2,920                       -168   -5.44%   x 1.06
 btree::set::difference_staggered_100_vs_100  2,206               1,820                       -386  -17.50%   x 1.21
 btree::set::difference_staggered_10k_vs_10k  218,622             181,240                  -37,382  -17.10%   x 1.21
 btree::set::intersection_100_neg_vs_100_pos  29                  27                            -2   -6.90%   x 1.07

@ssomers
Copy link
Contributor Author

ssomers commented Feb 4, 2020

So I can tweak the missing bits, probably the anti-panic barrier (when it's clear that #67290 intends to do more than prevent leaks), possibly the box interface, but definitely not lift the Ord bound. Is it useful to continue? I am happy to admit defeat and close this PR.

@ssomers ssomers force-pushed the btree_drain_filter branch 2 times, most recently from 878105e to b0f4885 Compare February 9, 2020 22:49
@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 16, 2020
@JohnCSimon
Copy link
Member

Ping from triage: @ssomers sorry I can't tell if you've addressed the request from cuviper
If you have, can you mark the change as complete and set this to S-waiting-on-review ?

@ssomers ssomers requested a review from cuviper February 16, 2020 10:44
@ssomers
Copy link
Contributor Author

ssomers commented Feb 16, 2020

I don't know if or how I can change labels. This PR is definitely blocked by #68827, and perhaps by #67290 (though I argue that this drain_filter is like the others, and tests now that there are no leaks, so #67290 can decide to impose more semantics independently).

@bors
Copy link
Contributor

bors commented Feb 17, 2020

☔ The latest upstream changes (presumably #68781) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@mlodato517 mlodato517 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just swinging by with some optional doc-related comments, feel free to ignore any of them 👍

src/liballoc/collections/btree/map.rs Show resolved Hide resolved
src/liballoc/collections/btree/map.rs Outdated Show resolved Hide resolved
src/liballoc/collections/btree/map.rs Outdated Show resolved Hide resolved
src/liballoc/collections/btree/set.rs Show resolved Hide resolved
src/liballoc/tests/btree/set.rs Outdated Show resolved Hide resolved
@ssomers
Copy link
Contributor Author

ssomers commented Feb 26, 2020

Ping from triage: @ssomers sorry I can't tell if you've addressed the request from cuviper
If you have, can you mark the change as complete

Tried marking their, and then all. discussions as resolved: doesn't make any difference.

What needs to happen (apart from further reviewing) is:

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-02-26T15:30:48.9930082Z ========================== Starting Command Output ===========================
2020-02-26T15:30:48.9933077Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/3cbafc2f-0a66-4143-9642-6e03193d0463.sh
2020-02-26T15:30:48.9933422Z 
2020-02-26T15:30:48.9940778Z ##[section]Finishing: Disable git automatic line ending conversion
2020-02-26T15:30:48.9971986Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/68770/merge to s
2020-02-26T15:30:48.9976200Z Task         : Get sources
2020-02-26T15:30:48.9976568Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-02-26T15:30:48.9976861Z Version      : 1.0.0
2020-02-26T15:30:48.9977058Z Author       : Microsoft
---
2020-02-26T15:30:49.9998561Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-02-26T15:30:50.0004128Z ##[command]git config gc.auto 0
2020-02-26T15:30:50.0008986Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-02-26T15:30:50.0012890Z ##[command]git config --get-all http.proxy
2020-02-26T15:30:50.0018931Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/68770/merge:refs/remotes/pull/68770/merge
---
2020-02-26T16:02:45.2353403Z    Compiling alloc v0.0.0 (/checkout/src/liballoc)
2020-02-26T16:02:45.6202110Z error: unused doc comment
2020-02-26T16:02:45.6202859Z   --> src/liballoc/collections/btree/navigate.rs:34:5
2020-02-26T16:02:45.6203376Z    |
2020-02-26T16:02:45.6204081Z 34 |     /// Returns a handle to the KV right of the leaf edge, either in the leaf itself or
2020-02-26T16:02:45.6205456Z    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macros
2020-02-26T16:02:45.6206790Z    = note: `-D unused-doc-comments` implied by `-D warnings`
2020-02-26T16:02:45.6207689Z    = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion
2020-02-26T16:02:45.6208080Z 
2020-02-26T16:02:45.6246408Z error: unused doc comment
2020-02-26T16:02:45.6246408Z error: unused doc comment
2020-02-26T16:02:45.6247057Z   --> src/liballoc/collections/btree/navigate.rs:35:5
2020-02-26T16:02:45.6247581Z    |
2020-02-26T16:02:45.6248274Z 35 |     /// in a parent. If the leaf edge is the last one in the tree, returns the root node.
2020-02-26T16:02:45.6249350Z    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macros
2020-02-26T16:02:45.6251008Z    = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion
2020-02-26T16:02:45.6251423Z 
2020-02-26T16:02:45.6251971Z error: unused doc comment
2020-02-26T16:02:45.6252567Z   --> src/liballoc/collections/btree/navigate.rs:38:5
2020-02-26T16:02:45.6252567Z   --> src/liballoc/collections/btree/navigate.rs:38:5
2020-02-26T16:02:45.6253600Z    |
2020-02-26T16:02:45.6257116Z 38 |     /// Returns a handle to the KV left of the leaf edge, either in the leaf itself or
2020-02-26T16:02:45.6258950Z    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macros
2020-02-26T16:02:45.6260523Z    = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion
2020-02-26T16:02:45.6260913Z 
2020-02-26T16:02:45.6278933Z error: unused doc comment
2020-02-26T16:02:45.6279593Z   --> src/liballoc/collections/btree/navigate.rs:39:5
2020-02-26T16:02:45.6279593Z   --> src/liballoc/collections/btree/navigate.rs:39:5
2020-02-26T16:02:45.6280167Z    |
2020-02-26T16:02:45.6280873Z 39 |     /// in a parent. If the leaf edge is the first one in the tree, returns the root node.
2020-02-26T16:02:45.6281972Z    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macros
2020-02-26T16:02:45.6283550Z    = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion
2020-02-26T16:02:45.6283946Z 
2020-02-26T16:02:45.7576745Z    Compiling cfg-if v0.1.10
2020-02-26T16:02:45.8474493Z    Compiling rustc-demangle v0.1.16
---
2020-02-26T16:02:47.5062109Z   local time: Wed Feb 26 16:02:47 UTC 2020
2020-02-26T16:02:47.8588176Z   network time: Wed, 26 Feb 2020 16:02:47 GMT
2020-02-26T16:02:47.8591621Z == end clock drift check ==
2020-02-26T16:02:49.8386796Z 
2020-02-26T16:02:49.8453954Z ##[error]Bash exited with code '1'.
2020-02-26T16:02:49.8471050Z ##[section]Finishing: Run build
2020-02-26T16:02:49.8523485Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/68770/merge to s
2020-02-26T16:02:49.8529481Z Task         : Get sources
2020-02-26T16:02:49.8529768Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-02-26T16:02:49.8530050Z Version      : 1.0.0
2020-02-26T16:02:49.8530239Z Author       : Microsoft
2020-02-26T16:02:49.8530239Z Author       : Microsoft
2020-02-26T16:02:49.8530531Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-02-26T16:02:49.8530886Z ==============================================================================
2020-02-26T16:02:50.1976443Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-02-26T16:02:50.2023297Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/68770/merge to s
2020-02-26T16:02:50.2123904Z Cleaning up task key
2020-02-26T16:02:50.2125138Z Start cleaning up orphan processes.
2020-02-26T16:02:50.2293044Z Terminate orphan process: pid (4215) (python)
2020-02-26T16:02:50.2477511Z ##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors
Copy link
Contributor

bors commented Feb 26, 2020

☔ The latest upstream changes (presumably #67290) made this pull request unmergeable. Please resolve the merge conflicts.

@ssomers
Copy link
Contributor Author

ssomers commented Feb 26, 2020

Closing for now because the "merge conflict" (it's actually a change in documentation rules) is in fact in the commits of #68827, which now sits there looking innocent.

@joelpalmer
Copy link

Triaged

@Dylan-DPC-zz Dylan-DPC-zz added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 24, 2020
@ssomers
Copy link
Contributor Author

ssomers commented Mar 28, 2020

Ideally we should get rid of the Ord requirement

I don't disagree, but I don't understand what the fuss is about, when methods like new and clear have the same Ord bound, to the code's own regret.

Anyways, changes coming, after cleaning up in #70506.

@Amanieu
Copy link
Member

Amanieu commented Mar 28, 2020

The fuss isn't so much about the Ord bound itself but rather the fact that we waste time searching through the tree again when we already know (or at least can easily figure out) where the next item is.

@ssomers
Copy link
Contributor Author

ssomers commented Mar 29, 2020

Adapted to various recent changes. I don't know how to run benchmarks these days, so performance is a bit of a gamble.

@Mark-Simulacrum
Copy link
Member

IIRC, last I worked on this I had pretty good success with just doing cd src/liballoc && cargo +$MASTER_SHA bench --bench collectionsbenches, where the MASTER_SHA is the base commit on the master branch. I suspect nightly would work fairly often as well.

@ssomers
Copy link
Contributor Author

ssomers commented Mar 30, 2020

doing cd src/liballoc && cargo +$MASTER_SHA bench --bench collectionsbenches

(For those stumbling upon this, this "plus syntax" is explained by shepmaster on stackoverflow and nowhere else I can find. How you can squeeze a SHA1 into a toolchain specifcation, or install the toolchain of a SHA1, is still a mystery to me. But that doesn't matter because...)

I think this, or "cargo +nightly bench --bench collectionsbenches", will benchmark code already merged into the master branch, and not the code proposed in a PR, apart from the benchmark code itself? Fine if you're only inventing benchmarks, but pretty clumsy to find out if proposed code is up to it?

@Mark-Simulacrum
Copy link
Member

Mark-Simulacrum commented Mar 30, 2020

You can install the toolchain off a PR if there's a try build available via rustup-toolchain-install-master; locally most folks working on the compiler have a link setup, as seen in rustup toolchain help link.

The SHA syntax will also work for any master commit, so long as the author is bors (i.e. merge commits by bors); indeed, the same is true for try builds -- you need the sha of the bors try commit.

'path' specifies the directory where the binaries and libraries for
the custom toolchain can be found. For example, when used for
development of Rust itself, toolchains can be linked directly out of
the build directory. After building, you can test out different
compiler versions as follows:

    $ rustup toolchain link latest-stage1 build/x86_64-unknown-linux-gnu/stage1
    $ rustup override set latest-stage1

If you now compile a crate in the current directory, the custom
toolchain 'latest-stage1' will be used.

And, no, the benchmarks should run code in the relevant crate (cargo should pass --extern crate=target/.../.rlib or so), in this case liballoc. I think I verified this, but I might be misremembering. (It should be easy to check by e.g. adding a panic! to BTreeMap::new or something).

@RalfJung
Copy link
Member

For those stumbling upon this, this "plus syntax" is explained by shepmaster on stackoverflow and nowhere else I can find.

FWIW, it is also documented at https://github.com/rust-lang/rustup#toolchain-override-shorthand and in

$ rustup run --help
rustup-run 
Run a command with an environment configured for a given toolchain

USAGE:
    rustup run [FLAGS] <toolchain> <command>...

FLAGS:
    -h, --help       Prints help information
        --install    Install the requested toolchain if needed

ARGS:
    <toolchain>     Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see `rustup help
                    toolchain`
    <command>...    

DISCUSSION:
    Configures an environment to use the given toolchain and then runs
    the specified program. The command may be any program, not just
    rustc or cargo. This can be used for testing arbitrary toolchains
    without setting an override.

    Commands explicitly proxied by `rustup` (such as `rustc` and
    `cargo`) also have a shorthand for this available. The toolchain
    can be set by using `+toolchain` as the first argument. These are
    equivalent:

        $ cargo +nightly build

        $ rustup run nightly cargo build

If you ave a good idea for other places this would be worth mentioning, I am sure we can make that happen. :)

@ssomers
Copy link
Contributor Author

ssomers commented Mar 30, 2020

If you ave a good idea for other places this would be worth mentioning, I am sure we can make that happen. :)

I definitely expected to find it in The Cargo Book > Cargo Commands > General Commands > cargo, but all I found in the book were examples using it.

@ssomers
Copy link
Contributor Author

ssomers commented Mar 30, 2020

$ rustup toolchain link latest-stage1 build/x86_64-unknown-linux-gnu/stage1

Great, I got that working now.

(It should be easy to check by e.g. adding a panic! to BTreeMap::new or something).

No need in this PR: it's enough if the new benchmarks of drain_filter compile.

Current results seem more stable and desirable:

>cargo benchcmp old4.txt new4.txt --threshold 5
 name                                           old4.txt ns/iter  new4.txt ns/iter  diff ns/iter   diff %  speedup
 btree::map::find_seq_10_000                    44                40                          -4   -9.09%   x 1.10
 btree::map::first_and_last_0                   31                34                           3    9.68%   x 0.91
 btree::map::insert_rand_100                    35                42                           7   20.00%   x 0.83
 btree::map::insert_rand_10_000                 35                42                           7   20.00%   x 0.83
 btree::map::insert_seq_100                     47                51                           4    8.51%   x 0.92
 btree::map::iter_mut_1000                      3,943             4,352                      409   10.37%   x 0.91
 btree::map::range_included_included            394,675           415,040                 20,365    5.16%   x 0.95
 btree::map::range_included_unbounded           1,786             1,626                     -160   -8.96%   x 1.10
 btree::map::range_unbounded_unbounded          3                 2                           -1  -33.33%   x 1.50
 btree::set::clone_100_and_drain_half           3,564             2,720                     -844  -23.68%   x 1.31
 btree::set::clone_10k_and_drain_half           494,560           310,650               -183,910  -37.19%   x 1.59
 btree::set::intersection_staggered_100_vs_10k  2,137             2,294                      157    7.35%   x 0.93
WARNING: benchmarks in new but not in old: btree::set::clone_100_and_drain_all, btree::set::clone_10k_and_drain_all

i.e. no genuine difference, only the :clone_*_and_drain_half benchmarks that compare to a naive implementation.

@RalfJung
Copy link
Member

Hm, this is not a cargo feature but a rustup feature, which is probably the source of the confusion here. It works with all rustup binaries: rustc +nightly also works, for example.

@Amanieu
Copy link
Member

Amanieu commented Mar 31, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Mar 31, 2020

📌 Commit 0405db3 has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 31, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 31, 2020
BTreeMap/BTreeSet: implement drain_filter

Provide an implementation of drain_filter for BTreeMap and BTreeSet. Should be optimal when the predicate picks only elements in leaf nodes with at least MIN_LEN remaining elements, which is a common case, at least when draining only a fraction of the map/set, and also when the predicate picks elements stored in internal nodes where the right subtree can easily let go of a replacement element.

The first commit adds benchmarks with an external, naive implementation. to compare how much this claimed optimality-in-some-cases is actually worth.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 31, 2020
Rollup of 6 pull requests

Successful merges:

 - rust-lang#68770 (BTreeMap/BTreeSet: implement drain_filter )
 - rust-lang#70081 (add `unused_braces` lint)
 - rust-lang#70556 (parse_and_disallow_postfix_after_cast: account for `ExprKind::Err`.)
 - rust-lang#70605 (Add missing -lmsvcrt on mingw after -lpthread)
 - rust-lang#70630 (Update books.)
 - rust-lang#70632 (expand vec![] to Vec::new())

Failed merges:

r? @ghost
@bors bors merged commit 718ba0d into rust-lang:master Apr 1, 2020
@ssomers ssomers deleted the btree_drain_filter branch July 16, 2020 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.