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

[Deque] append(contentsOf:): Use exponential capacity reservation #113

Merged
merged 1 commit into from
Nov 16, 2021

Conversation

lorentey
Copy link
Member

Depending on the supplied sequence, Deque.append(contentsOf:) currently reserves just enough capacity as it needs to perform the append. This isn't right -- it can result in O(n) reallocs instead of O(log(n)) when items are incrementally appended in constant-sized append(contents:) batches.

Checklist

  • I've read the Contribution Guidelines
  • My contributions are licensed under the Swift license.
  • I've followed the coding style of the rest of the project.
  • I've added tests covering all new code paths my change adds to the project (if appropriate).
  • I've added benchmarks covering new functionality (if appropriate).
  • I've verified that my change does not break any existing tests or introduce unexplained benchmark regressions.
  • I've updated the documentation if necessary.

@lorentey
Copy link
Member Author

@swift-ci test

@lorentey
Copy link
Member Author

We'll need to figure out how to test this sort of allocation behavior. The obvious thing is to add some counters to the storage buffer in SWIFT_COLLECTIONS_INTERNAL_CHECKS builds.

@lorentey lorentey modified the milestones: 1.0.1, 1.0.2 Nov 1, 2021
@lorentey lorentey mentioned this pull request Nov 16, 2021
Depending on the supplied sequence, `Deque.append(contentsOf:)` currently reserves just enough capacity as it needs to perform the append. This isn't right -- it can result in O(n) reallocs instead of O(log(n)) when items are incrementally appended in constant-sized `append(contents:)` batches.
@lorentey lorentey changed the base branch from main to release/1.0 November 16, 2021 00:13
@lorentey
Copy link
Member Author

@swift-ci test

@lorentey lorentey merged commit 4825482 into apple:release/1.0 Nov 16, 2021
@lorentey lorentey deleted the deque-scaling branch November 16, 2021 00:16
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.

1 participant