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

Make "belongsTo" create virtual components by default #6452

Merged
merged 3 commits into from
Aug 22, 2018

Conversation

melix
Copy link
Contributor

@melix melix commented Aug 21, 2018

Context

This PR is a performance optimization: it makes sure that platforms declared via belongsTo in a rule are assumed virtual. By doing so, we avoid polling external repositories to check if a module exists or not.

The belongsTo(Object, boolean) method can be used to "restore" the previous behavior. By using false as a parameter, we declare that the target platform is either published, or we don't know. The consequence is that the engine would ping the external repository to check, and therefore initiate network requests like it did before this PR.

Implementation-wise, this PR wraps a ComponentIdentifier by marking it with a special interface.

@melix melix added this to the 5.0 RC1 milestone Aug 21, 2018
@melix melix self-assigned this Aug 21, 2018
@melix melix requested review from ljacomet and bigdaz August 21, 2018 11:31
* @param id the original component identifier
* @return a virtual component identifier
*/
public static VirtualComponentIdentifier makeVirtual(final ComponentIdentifier id) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there really no solution simpler than a dynamic proxy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't find any obvious one, but I'm open to suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe there is for now no need to be this generic and we can verify that belongsTo only produces DefaultModuleComponentIdentifier and replace these with a VirtualModuleComponentIdentifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah but it would introduce a very specific type for this. I'm not sure I like it more.

Copy link
Member

Choose a reason for hiding this comment

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

❌ I don't really like this sort of magic. Maybe I'm just too "traditional".
How about:
a) Fail if belongsTo is called with anything other than a ModuleComponentIdentifier
b) Use a concrete wrapper that implements VirtualComponentIdentifier
c) Maybe make VirtualComponentIdentifier extends ModuleComponentIdentifier

* @param id the original component identifier
* @return a virtual component identifier
*/
public static VirtualComponentIdentifier makeVirtual(final ComponentIdentifier id) {
Copy link
Member

Choose a reason for hiding this comment

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

❌ I don't really like this sort of magic. Maybe I'm just too "traditional".
How about:
a) Fail if belongsTo is called with anything other than a ModuleComponentIdentifier
b) Use a concrete wrapper that implements VirtualComponentIdentifier
c) Maybe make VirtualComponentIdentifier extends ModuleComponentIdentifier

* that we never "find" a virtual component, by shortcutting resolution if we find the marker interface
* for virtual components.
*/
class VirtualComponentMetadataResolver implements ComponentMetaDataResolver {
Copy link
Member

Choose a reason for hiding this comment

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

To me, this is much better than the 'discovery' of virtual components.

Now that we know up-front if a component is virtual or not, I'd like to revert the changes made in #5957. If a platform is not virtual, then we should fail if it does not resolve. I suspect that we've left the fallback code in place to construct a virtual platform if we are told (via belongsTo("", false) that a platform is published and it turns out to be missing.

The retryIfMissing boolean is the sort of complexity that might seem harmless enough, but could cause us pain further down the line.

@melix melix changed the base branch from cc/dm/forcing-platforms to master August 22, 2018 13:23
This commit changes the behavior of "belongsTo" in component metadata rules,
so that it creates a virtual platform by default. By doing this, we optimize
the engine which can now avoid checking for a real, published platform,
avoiding costly repository calls to fetch metadata.

If a component needs to declare that it participates in a published platform,
or if we don't know if the platform is published or not, then the alternate,
new `belongsTo(id, virtual)` method needs to be called.

This is a performance optimization only.

Closes #6447
@melix
Copy link
Contributor Author

melix commented Aug 22, 2018

@ljacomet @bigdaz ready for 2d look

Copy link
Member

@ljacomet ljacomet left a comment

Choose a reason for hiding this comment

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

Only a naming comment, not blocking for a merge if the suggestion is not applied.

import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.internal.DisplayName;

public class DefaultVirtualModuleComponentIdentifier implements VirtualComponentIdentifier, ModuleComponentIdentifier, DisplayName {
Copy link
Member

Choose a reason for hiding this comment

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

I would drop the Default from the name, leaving VirtualModuleComponentIdentifier

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd better leave it as it would be inconsistent with the current naming strategy.

Copy link
Member

@bigdaz bigdaz left a comment

Choose a reason for hiding this comment

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

LGTM. I'm amazed that no tests needed to change when we removed the retryIfMissing flag: I guess we were already using the correct belongsTo variant in all cases?

@melix
Copy link
Contributor Author

melix commented Aug 22, 2018

Yes, I had changed the uses of belongsTo in a previous commit.

This commit removes the ability of the engine to determine that a platform
is virtual when it's not marked as such. This means that we effectively
trust the user calling the right `belongsTo` method. By doing this, it
allows us to remove the `retryIfMissing` complexity.
@melix melix merged commit 2e09db7 into master Aug 22, 2018
@melix melix deleted the cc/dm/always-virtual branch August 22, 2018 22:30
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.

3 participants