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 performance of currentVersion by caching #346

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JozoVilcek
Copy link

No description provided.

@JozoVilcek
Copy link
Author

@adamdubiel there is a failing test still but I wanted to get an opinion in advance if this approach is going the way which is acceptable for the plugin.


RevCommit currentCommit;
List<String> currentTagsList;
for (currentCommit = walk.next(); currentCommit != null; currentCommit = walk.next()) {
Copy link
Author

Choose a reason for hiding this comment

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

I am not quite sure if this simplification is not having some serious drawbacks

Copy link
Author

Choose a reason for hiding this comment

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

I walker is to get the order of tags, which might not be needed for all cases. I tried to address it with latest.

@JozoVilcek JozoVilcek force-pushed the improve-configuration-phase-performance branch from 723f7a6 to 8c1448d Compare July 18, 2020 12:54
@JozoVilcek JozoVilcek force-pushed the improve-configuration-phase-performance branch from 8c1448d to 85f5be6 Compare July 18, 2020 13:18
@coveralls
Copy link

Coverage Status

Coverage increased (+0.9%) to 58.598% when pulling 85f5be6 on JozoVilcek:improve-configuration-phase-performance into 21368b6 on allegro:master.

@@ -169,7 +169,7 @@ class GitRepositoryTest extends Specification {
List<TagsOnCommit> allTaggedCommits = repository.taggedCommits(~/^release.*/)

then:
allTaggedCommits.collect { c -> c.tags[0] } == ['release-3', 'release-4', 'release-2', 'release-1']
allTaggedCommits.collect { c -> c.tags[0] }.toSet() == ['release-3', 'release-4', 'release-2', 'release-1'].toSet()
Copy link
Author

Choose a reason for hiding this comment

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

Is this OK or are tags inside TagsOnCommit required to be in ordered?

@JozoVilcek
Copy link
Author

@adamdubiel will you get some time to review this if the approach is acceptable?

@JozoVilcek
Copy link
Author

@adamdubiel do you have some estimate when you might get some time to review this?

JozoVilcek pushed a commit to JozoVilcek/axion-release-plugin that referenced this pull request Aug 30, 2020
@bgalek
Copy link
Member

bgalek commented Feb 13, 2021

@JozoVilcek Hi, thanks for your contribution!
I've just merged gradle update - this plugin should support incremental build and gradle caches, do you think it would resolve the issue? :)

@JozoVilcek
Copy link
Author

@bgalek By a brief look, I was not able to find the patch which might be related to this. Can you share the merge request URL?

@bgalek
Copy link
Member

bgalek commented Feb 15, 2021

@JozoVilcek
117ba7d
@Input annotations should allow gardle to cache outputs of task (I didn't yet tested it out for incremental builds, but this had to be done anyway for latest gradle version compliance).
I know, that it's not directly connected to your PR but I hope, there will be a performance improvement ;)

@JozoVilcek
Copy link
Author

@bgalek, I am sorry, it took me quite a bit time to get back to you.

So I did try the current master on the project I use. I executed ./gradlew --dry-run --profile clean and configuration phase took:

  • my patch -> ~51 seconds
  • master -> ~ 4 minutes 31 seconds

@bgalek
Copy link
Member

bgalek commented Mar 10, 2021

@JozoVilcek that's quite an improvement! I'll look at this PR in a few days!

public class ScmCache {

/**
* Since this cache is statis and Gradle Demon might keep JVM process in background for a long
Copy link

Choose a reason for hiding this comment

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

some typos
statis -> static
Demon - Daemon

* Since this cache is statis and Gradle Demon might keep JVM process in background for a long
* time, we have to put some TTL for cached values.
*/
private static final long INVALIDATE_AFTER_MILLIS = 1000 * 60;
Copy link
Member

Choose a reason for hiding this comment

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

please use Duration ;)

@@ -0,0 +1,106 @@
package pl.allegro.tech.build.axion.release.infrastructure.git;

import groovy.lang.Tuple2;
Copy link
Member

Choose a reason for hiding this comment

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

i think we should not use groovy in java classes ;)


private ScmCache() { }

private final Map<String, CachedState> cache = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

when a ScmCache hashmap will have more than one key?

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure if it can happen somehow that this singleton will get involved in mixed/multiple projects. This is coming from the inception work I picked up and continued:
48e2371

Do you have suggestion for a change?

cache.remove(repository.id());
}

public synchronized boolean checkUncommittedChanges(ScmRepository repository) {
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't a concurrent hash map be better than a synchronized block?

Copy link
Author

Choose a reason for hiding this comment

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

possibly. do you think it will be noticeable improvement?

/**
* Provides cached version for some operations on {@link ScmRepository}
*/
public class ScmCache {
Copy link
Member

Choose a reason for hiding this comment

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

what do you think about enum based singletons? also it would be nice if this class would be package-private ;)

Copy link
Author

Choose a reason for hiding this comment

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

It can not be easily package private right now as it is accessed from VersionResolver. Do you have suggestion how to move necessary classes so ti encapsulates better?

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.

4 participants