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

Do not allocate for RelativeDistinguishedNames with just a single attribute #101

Merged
merged 46 commits into from
Jul 5, 2023

Conversation

dnadoba
Copy link
Member

@dnadoba dnadoba commented Jun 21, 2023

Motivation

A RelativeDistinguishedName has almost always just a single Attribute but we currently always allocate an array.

Modification

  • Use _TinyArray instead of Array as the internal storage for Attributes in RelativeDistinguishedName
  • lazily decode nodes. We needed to copy over some code from swift-asn1. We might want to think about porting it back to swift-asn1 but need to think about the right public API for that which we can start in this PR.
  • RelativeDistinguishedName init can't fail and therefore it is now non-throwing init

Result

Allocations have improved

dnadoba added 30 commits June 13, 2023 13:45
Conflicts:
	IntegrationTests/run-tests.sh
	IntegrationTests/tests_01_allocation_counters/test_01_resources/shared.swift
	docker/docker-compose.2204.57.yaml
	docker/docker-compose.2204.58.yaml
	docker/docker-compose.2204.59.yaml
	docker/docker-compose.2204.main.yaml
# Conflicts:
#	IntegrationTests/run-tests.sh
#	IntegrationTests/tests_01_allocation_counters/test_01_resources/run-swift-certificates-alloc-counter-tests.sh
#	IntegrationTests/tests_01_allocation_counters/test_01_resources/shared.swift
#	Tests/X509Tests/TinyArrayTests.swift
#	docker/docker-compose.2204.57.yaml
#	docker/docker-compose.2204.58.yaml
#	docker/docker-compose.2204.59.yaml
#	docker/docker-compose.2204.main.yaml
and apply review feedback
# Conflicts:
#	IntegrationTests/tests_01_allocation_counters/test_01_resources/test_tiny_array_cow_append_contents_of.swift
#	IntegrationTests/tests_01_allocation_counters/test_01_resources/test_tiny_array_non_allocating_operations.swift
#	Sources/X509/TinyArray.swift
#	Sources/X509/_TinyArray.swift
#	Sources/_CertificateInternals/_TinyArray.swift
#	docker/docker-compose.2204.57.yaml
#	docker/docker-compose.2204.58.yaml
#	docker/docker-compose.2204.59.yaml
#	docker/docker-compose.2204.main.yaml
dnadoba added 8 commits June 20, 2023 10:37
# Conflicts:
#	IntegrationTests/tests_01_allocation_counters/test_01_resources/test_tiny_array_cow_append_contents_of.swift
#	docker/docker-compose.2204.57.yaml
#	docker/docker-compose.2204.58.yaml
#	docker/docker-compose.2204.59.yaml
#	docker/docker-compose.2204.main.yaml
# Conflicts:
#	docker/docker-compose.2204.57.yaml
#	docker/docker-compose.2204.58.yaml
#	docker/docker-compose.2204.59.yaml
#	docker/docker-compose.2204.main.yaml
@dnadoba dnadoba added the 🆕 semver/minor Adds new public API. label Jun 21, 2023
dnadoba added 2 commits June 21, 2023 08:42
# Conflicts:
#	docker/docker-compose.2204.57.yaml
#	docker/docker-compose.2204.58.yaml
#	docker/docker-compose.2204.59.yaml
#	docker/docker-compose.2204.main.yaml
/// - rootNode: The ``ASN1Node`` to parse
/// - returns: An array of elements representing the elements in the sequence.
@inlinable
public static func lazySet<T: DERParseable>(of: T.Type = T.self, identifier: ASN1Identifier, rootNode: ASN1Node) throws -> some Sequence<Result<T, Error>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's pretty unfortunate to have to add this, and its supporting code, here: doubly so that we've made it public. Can we push this down into ASN1?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes sure, I just didn't like that particular name and couldn't come up with a better one.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

@dnadoba
Copy link
Member Author

dnadoba commented Jul 4, 2023

@swift-server-bot test this please

dnadoba added 3 commits July 4, 2023 10:49
# Conflicts:
#	docker/docker-compose.2204.57.yaml
#	docker/docker-compose.2204.58.yaml
#	docker/docker-compose.2204.59.yaml
@dnadoba
Copy link
Member Author

dnadoba commented Jul 4, 2023

Allocations are reduce by ~7% for parsing certificates 93b35b8

@dnadoba
Copy link
Member Author

dnadoba commented Jul 4, 2023

Looks like the nightly toolchain is still pulling in swift-asn1 0.9.1. Let's see if a rerun fixes it.
Actually the update script is broken and hasn't update the allocations in #107. Fixing this now in this PR.
@swift-server-bot test this please

@dnadoba
Copy link
Member Author

dnadoba commented Jul 4, 2023

@swift-server-bot test this please

@dnadoba
Copy link
Member Author

dnadoba commented Jul 4, 2023

API breakage checker failure is a bug in swift: swiftlang/swift#67113

}

@inlinable
init(_ attributes: some Sequence<Result<RelativeDistinguishedName.Attribute, some Error>>) throws {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this to be fully generic? Or can we just accept the actual type?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, have changed it: d2ca572

@Lukasa Lukasa merged commit 290123d into apple:main Jul 5, 2023
@dnadoba dnadoba deleted the dn-collection-of-one-or-more branch August 26, 2024 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants