Skip to content

Use binary search for removing elements from Bag - #878

Merged
mluisbrown merged 3 commits into
ReactiveCocoa:masterfrom
nickoto:nick/bag_performance
Oct 11, 2023
Merged

Use binary search for removing elements from Bag#878
mluisbrown merged 3 commits into
ReactiveCocoa:masterfrom
nickoto:nick/bag_performance

Conversation

@nickoto

@nickoto nickoto commented Sep 14, 2023

Copy link
Copy Markdown
Contributor

Given that tokens are always added to the end of the array and have a monotonically increasing value, this list is always sorted, so we can use a binary search to improve performance if this list gets large.

Checklist

  • Updated CHANGELOG.md.

Given that tokens are always added to the end of the array and have a monotonically
increasing value, this list is always sorted, so we can use a binary search to improve
performance if this list gets large.
@mluisbrown

Copy link
Copy Markdown
Contributor

@nickoto did you run any tests to validate the performance improvement, and how significant it is? It would be useful to have some metrics.

@nickoto

nickoto commented Sep 15, 2023

Copy link
Copy Markdown
Contributor Author

Yes; in our particular scenario instruments was showing that for this particular operation in our app that Bag.remove was by far the hot path, taking several seconds to complete removing a large number of elements from the bag. After this change the removal process time went to several milliseconds in the exact same scenario. (In this case, the bag contained thousands of elements and the operation was removing half of them at once in no particular order).

While I can't test this over all workloads, in any situation where many items would be removed from the bag at once e.g. a large teardown, this would be a benefit. In situations where the bag is very tiny the complexity cost is negligible.

@mluisbrown mluisbrown left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like a good improvement 👍

@nickoto
nickoto requested a review from mluisbrown September 27, 2023 15:31
@nickoto

nickoto commented Sep 27, 2023

Copy link
Copy Markdown
Contributor Author

@mluisbrown Since the runner for ubuntu 18.04 is deprecated we can no longer run the SwiftPM tests for 5.2 as there is no binary release of swift 5.2 on that platform (it only has releases for 16.04 and 18.04). That's why the log is showing a 404 - it fails to download a release that doesn't exist.

Not sure why the 5.7 runner was cancelled though -- it looks like it was passing up until it cancelled.

@mluisbrown

Copy link
Copy Markdown
Contributor

@nickoto We should drop the 5.2 tests then. I'm not sure if you have the rights to do that. If not let me know and I'll sort it out.

@nickoto

nickoto commented Sep 27, 2023

Copy link
Copy Markdown
Contributor Author

I can drop it from the yml but I'm not sure if there are other steps required.

Update: Yea I don't think I can get any further on my own, I don't even have permission to approve running the workflow @mluisbrown.

@mluisbrown
mluisbrown merged commit 74dce06 into ReactiveCocoa:master Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants