Skip to content

Conversation

finestructure
Copy link
Member

Fix for slow runtime: more than half the time spent in WebpageSnapshotTests was spent in MaintainerInfoIndex_document (5s out of 10s on my machine).

@cla-bot cla-bot bot added the cla-signed label Mar 5, 2025
}

var scoreCategories: [PackageScore] {
func scoreCategories() -> [PackageScore] {
Copy link
Member Author

@finestructure finestructure Mar 5, 2025

Choose a reason for hiding this comment

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

scoreCategories is not a cheap computation and it's best practice not to make them properties - sort of to signal that they're not cheap.

.p("\(scoreCategories[index].description)")
.p("\(categories[index].title)"),
.p("\(categories[index].score) points"),
.p("\(categories[index].description)")
Copy link
Member Author

@finestructure finestructure Mar 5, 2025

Choose a reason for hiding this comment

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

The problem is here - this function used the somewhat expensive scoreCategories multiple times and in a loop, leading to noticeably bad performance.

Making the function static makes it easy to re-use the externally computed value here. This way, there's no risk it can again accidentally be called multiple times without being aware of the cost.

@finestructure finestructure merged commit f379cd2 into main Mar 5, 2025
5 of 6 checks passed
@finestructure finestructure deleted the fix-MaintainerInfoIndex-performance branch March 5, 2025 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants