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

[NFC] Clean up package graph caching code #7128

Closed
wants to merge 4 commits into from

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Nov 28, 2023

Motivation:

Depends on #7127.

Resolved* types in the PackageGraph module were confusingly named as Resolved*Builder, while they had no relation to the established builder pattern in Swift. In fact, these types are doing only caching, although proxying a few properties to initializer calls. The impact of this proxying remains to be benchmarked, as I have suspicion that these types specifically don't bring a significant speed up, but only introduce a redundant level of indirection.

Modifications:

I've renamed these types to explicitly mention caching and moved them out to a separate directory.

Result:

It's easier to understand that caching is being used. Relevant caching types are easier to find.

This protocol doesn't define any requirements and was used for nemaspacing a single tuple typealias. Instead of typealiasing this fairly complex and pervasively used tuple, we should define a separate struct for it. Then the protocol itself can be removed as completely unused.

Also used this as an opportunity to clean up file naming and directory layout in the `PackageGraph` module.
`Resolved*` types in the `PackageGraph` module were confusingly named as `Resolved*Builder`, while they had no relation to [the established builder pattern](https://www.swiftbysundell.com/articles/using-the-builder-pattern-in-swift/) in Swift. In fact, these types are doing only memoization, although proxying a few properties to initializer calls. The impact of this proxying remains to be benchmark, as I have suspicion that these types specifically don't bring a significant speed up, but only introduce a redundant level of indirection.

In the meantime I've renamed these types to explicitly mention memoization and moved them out to a separate directory.
@MaxDesiatov MaxDesiatov added the no functional change No user-visible functional changes included label Nov 28, 2023
@MaxDesiatov MaxDesiatov self-assigned this Nov 28, 2023
@tomerd
Copy link
Contributor

tomerd commented Nov 28, 2023

👍 this is a good change! also agree these types add complexity and are is not necessarily adding value.

one thought, should we consider calling them "CachedXxx" instead of "MemoizedXxx"?

@MaxDesiatov MaxDesiatov changed the title [NFC] Clean up package graph memoization code [NFC] Clean up package graph caching code Nov 28, 2023
Base automatically changed from maxd/cleanup-dependency-resolver to main November 30, 2023 18:37
@MaxDesiatov
Copy link
Contributor Author

MaxDesiatov commented Dec 2, 2023

Closing as superseded by #7160. After refactoring this code I found that in a convoluted way these actually are "builder" types, but they rely on multiple side effects of other reference types in PackageGraph and PackageModel modules.

They defer package graph construction until all of the side effects (including module aliasing) are applied, after which actual Resolved* values are created.

MO these types should be just plainly removed, but only after these side effects are cleaned up, otherwise we'd break module aliasing, which relies on reference types semantics and side effects.

@MaxDesiatov MaxDesiatov closed this Dec 2, 2023
@MaxDesiatov MaxDesiatov deleted the maxd/pacakge-graph-memoization branch December 2, 2023 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no functional change No user-visible functional changes included
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants