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

Improve json generation performance (tweaked #2035) #2105

Conversation

alexarchambault
Copy link
Member

@alexarchambault alexarchambault commented Jul 7, 2021

Includes #2035

depToTransitiveDeps(elem)
else {
val children0 = children(elem)
val deps = children0.map(reconciledVersionStr(_)).toSet ++ children0.iterator.flatMap(flattenDeps(_))
Copy link
Contributor

@kitterion kitterion Jul 7, 2021

Choose a reason for hiding this comment

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

In my original PR I thought about using .flatMap on children0 but decided against it because it seems to require O(n^2) memory on dense graphs where n is the size of children0 and the whole point was to minimize memory consumption.
My logic is that in a fully connected directed acyclic graph .flatMap will generate a sequence of size (n-2) + (n-3) + ... + 1 + 0 = (n-2)(n-1)/2 ~ n^2, and only after generating that sequence will it collapse while being converted to Set.

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, but we flatMap on an iterator here, so no large collection actually gets built, I believe. flattenDeps gets called on the first element of children0, the corresponding set is added to the one being built for deps and discarded straightaway, then the next element of children0 is processed, etc.

@alexarchambault alexarchambault force-pushed the improve-json-generation-performance branch from 0c82ab5 to 21bad4f Compare August 31, 2021 12:35
@alexarchambault alexarchambault marked this pull request as ready for review August 31, 2021 19:37
@alexarchambault alexarchambault merged commit 276a1b7 into coursier:master Aug 31, 2021
@alexarchambault alexarchambault deleted the improve-json-generation-performance branch August 31, 2021 19:37
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.

None yet

2 participants