Skip to content

BTreeMap: reuse BoxedNode instances directly instead of their contents - #77408

Closed
ssomers wants to merge 1 commit into
rust-lang:masterfrom
ssomers:btree_cleanup_6
Closed

BTreeMap: reuse BoxedNode instances directly instead of their contents #77408
ssomers wants to merge 1 commit into
rust-lang:masterfrom
ssomers:btree_cleanup_6

Conversation

@ssomers

@ssomersssomers commented Oct 1, 2020

Copy link
Copy Markdown
Contributor

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 1, 2020
@ssomers

Copy link
Copy Markdown
ContributorAuthor

Benchmarks pretend to be a bit faster, despite push/pop being relatively rare.

 name old ns/iter new ns/iter diff ns/iter diff % speedup
btree::map::clone_fat_100_and_into_iter 73,040 70,605 -2,435 -3.33% x 1.03
btree::map::insert_rand_10_000 33 31 -2 -6.06% x 1.06
btree::map::insert_seq_10_000 96 90 -6 -6.25% x 1.07
btree::map::iteration_mut_20 69 66 -3 -4.35% x 1.05
btree::set::clone_100_and_clear 1,833 1,776 -57 -3.11% x 1.03
btree::set::clone_100_and_into_iter 1,820 1,764 -56 -3.08% x 1.03
btree::set::clone_10k_and_remove_half 447,705 429,720 -17,985 -4.02% x 1.04
btree::set::intersection_random_10k_vs_100 2,153 2,085 -68 -3.16% x 1.03

@camelidcamelid added the T-libs-api [DEPRECATED; DO NOT USE] label Oct 1, 2020
Comment threadlibrary/alloc/src/collections/btree/node.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels like we're (potentially) doing needless work -- this looks equivalent to internal_node.edges[0].assume_init_read() which avoids the spurious write to edges -- can we use that instead?

(I suspect in practice LLVM probably ignores writing uninitialized data to some region of memory, but not sure).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Indeed and I did the logical equivalent ptr::read on the other side.

@Mark-SimulacrumMark-Simulacrum 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 Oct 4, 2020
@ssomers

Copy link
Copy Markdown
ContributorAuthor

Swapped the 2 commits here and based on #77471 to avoid a benign conflict

@ssomers
ssomers marked this pull request as draft October 5, 2020 11:24
@ssomers

Copy link
Copy Markdown
ContributorAuthor

Nothing wrong, just easier to follow if I do the first commit separately.

JohnTitor added a commit to JohnTitor/rust that referenced this pull request Oct 13, 2020
…ulacrum
BTreeMap: type-specific variants of node_as_mut and cast_unchecked
Improves debug checking and shortens some expressions. Extracted from rust-lang#77408
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Oct 13, 2020
…ulacrum
BTreeMap: type-specific variants of node_as_mut and cast_unchecked
Improves debug checking and shortens some expressions. Extracted from rust-lang#77408
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Oct 13, 2020
…ulacrum
BTreeMap: type-specific variants of node_as_mut and cast_unchecked
Improves debug checking and shortens some expressions. Extracted from rust-lang#77408
@ssomersssomers changed the title BTreeMap: avoid sneaky clones of BoxedNodeBTreeMap: reuse BoxedNode instances directly instead of their contents Oct 14, 2020
@ssomers
ssomers marked this pull request as ready for review October 14, 2020 10:29
@ssomers

Copy link
Copy Markdown
ContributorAuthor

Still showing the same improvement, but now with the opposite on sets.

 name old ns/iter new ns/iter diff ns/iter diff % speedup
btree::map::clone_slim_100 2,043 2,106 63 3.08% x 0.97
btree::map::clone_slim_100_and_clear 2,551 2,065 -486 -19.05% x 1.24
btree::map::clone_slim_100_and_drain_all 3,891 3,441 -450 -11.57% x 1.13
btree::map::clone_slim_100_and_drain_half 3,351 2,844 -507 -15.13% x 1.18
btree::map::clone_slim_100_and_into_iter 2,587 2,045 -542 -20.95% x 1.27
btree::map::clone_slim_100_and_pop_all 3,684 3,189 -495 -13.44% x 1.16
btree::map::clone_slim_100_and_remove_all 4,515 4,044 -471 -10.43% x 1.12
btree::map::clone_slim_100_and_remove_half 3,388 2,823 -565 -16.68% x 1.20
btree::set::clone_100_and_remove_all 3,397 3,792 395 11.63% x 0.90
btree::set::clone_10k_and_remove_all 400,900 436,475 35,575 8.87% x 0.92

@ssomers

Copy link
Copy Markdown
ContributorAuthor

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@rustbotrustbot 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 Oct 16, 2020
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+ rollup=never

@bors

bors commented Oct 19, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit 184735a has been approved by Mark-Simulacrum

@borsbors 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 Oct 19, 2020
@Mark-Simulacrum

Copy link
Copy Markdown
Member

Oh, hm, I just saw that #78104 lists itself as a better alternative to this. @bors r-

@borsbors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 20, 2020
@ssomers

ssomers commented Oct 20, 2020

Copy link
Copy Markdown
ContributorAuthor

Well I actually rebased #77244 on this anticipating it would arrive soon, so you approved it again…

It's mostly a logical alternative, explicitly not reusing rather than explicitly reusing, but it's easy enough to let #78104 overwrite this little change.

@Mark-Simulacrum

Copy link
Copy Markdown
Member

Okay. I don't mind the extra PR. @bors r+

@bors

bors commented Oct 20, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit 184735a has been approved by Mark-Simulacrum

@borsbors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 20, 2020
@bors

bors commented Oct 21, 2020

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 184735a with merge 8682c9fe0f1a3307f310ee5e5b4a66f93c5f9466...

@ssomers

Copy link
Copy Markdown
ContributorAuthor

#77244 was rebased on the same changes and made it through first. I wondered what bors would do and as far as I can tell it just turned away in disgust. The commit in #77244 is a different SHA-1 though, because it was rebased too.

@ssomersssomers closed this Oct 21, 2020
@ssomers
ssomers deleted the btree_cleanup_6 branch October 22, 2020 08:13
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@ssomers@Mark-Simulacrum@bors@rust-highfive@camelid@rustbot