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

bug(#3806): Add caching in UnphiMojo #4027

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

vl4ds4m
Copy link
Contributor

@vl4ds4m vl4ds4m commented Mar 20, 2025

Closes: #3806
This PR embeds caching in UnphiMojo and enables cache test cases in UnphiMojoTest. But there is unresolved problem: these classes use irrelevant hash (FAKE_HASH) because i can't understand how to use relevant one, so i need help to resolve it.

Copy link

github-actions bot commented Mar 20, 2025

🚀 Performance Analysis

Test Base Score PR Score Change % Change Unit Mode
benchmarks.XmirBench.xmirToEO 174.755 154.202 -20.554 -11.76% ms/op Average Time
benchmarks.XmirBench.xmirToPhi 159.520 163.123 3.602 2.26% ms/op Average Time
benchmarks.XmirBench.xmirToSaltyPhi 168.963 140.127 -28.836 -17.07% ms/op Average Time

✅ Performance gain: benchmarks.XmirBench.xmirToEO is faster by 20.554 ms/op (11.76%)
⚠️ Performance loss: benchmarks.XmirBench.xmirToPhi is slower by 3.602 ms/op (2.26%)
✅ Performance gain: benchmarks.XmirBench.xmirToSaltyPhi is faster by 28.836 ms/op (17.07%)

@vl4ds4m
Copy link
Contributor Author

vl4ds4m commented Mar 20, 2025

I changed names and descriptions of footprint classes, which compare lastModified values of files, as older means the file is expired, not actual. Also, isAfter in former FpIfTargetOlder is isNotBefore now because a target file created with the source file at the same time is also actual.

@vl4ds4m
Copy link
Contributor Author

vl4ds4m commented Mar 20, 2025

@maxonfjvipon please, review it

@maxonfjvipon
Copy link
Member

maxonfjvipon commented Mar 21, 2025

@vl4ds4m

  1. your build is not clear, before review please make sure all the checks are passed
  2. it looks like some of the changes are generated by AI. There's no any point to rename older to actual or isAfter to isNotBefore. So please remove them
  3. Try to use empty string instead of hash for now

@vl4ds4m
Copy link
Contributor Author

vl4ds4m commented Mar 21, 2025

@maxonfjvipon I fixed build and reverted unnecessary changes, but empty string hash isn't valid for passing UnphiMojoTest tests with cache

@@ -59,7 +59,7 @@ public final class FpIfTargetOlder extends FpEnvelope {
* @throws IOException If fails to compare files
*/
private static boolean isAfter(final Path first, final Path second) throws IOException {
return Files.getLastModifiedTime(first).toInstant().isAfter(
return !Files.getLastModifiedTime(first).toInstant().isBefore(
Copy link
Member

Choose a reason for hiding this comment

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

@vl4ds4m this change is unnecessary

void usesCache(@Mktmp final Path temp) throws Exception {
new Saved(
"{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}",
temp.resolve("target/eo/phi/std.phi")
).value();
final String hash = "123ZaRiFcHiK321";
final String hash = UnphiMojo.FAKE_HASH;
Copy link
Member

Choose a reason for hiding this comment

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

@vl4ds4m it's totally ok to slightly change the test after you introduce an implementation, let's try to use empty string here and in UnphiMojo because it doesn't depend on tojos

@@ -335,6 +329,11 @@ void invalidatesCache(@Mktmp final Path temp) throws Exception {
"{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}",
temp.resolve("target/eo/phi/std.phi")
).value();
MatcherAssert.assertThat(
"The cached file's last modified timestamp should be successfully reset",
cached.setLastModified(0L),
Copy link
Member

Choose a reason for hiding this comment

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

@vl4ds4m what's the reason to change this timestamp? Hard coded cached file was saved before the the original std.phi. So it'll be anyway younger

Comment on lines 35 to 41
/**
* Hash directory for unphied files.
*/
@SuppressWarnings("PMD.ImmutableField")
@Parameter(property = "eo.hash")
private String hash = "";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Introduced a field for hash with default empty value

Copy link
Member

Choose a reason for hiding this comment

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

@vl4ds4m it seems we have hash field in several mojos now, in ProbeMojo, in PullMojo and in UnphiMojo.
Let's make it only one by moving the field to the SafeMojo and make it protected so it'll look like:

abstract class SafeMojo {
  protected CommitHash hash = new ChConstant(
    new ChNarrow(new ChRemote(this.tag))
  );
}

I think when it's done - it'll require some tests fixes. We're almost good to merge

Comment on lines +299 to +303
MatcherAssert.assertThat(
"The cached file's last modified timestamp should be strictly after the source one",
cached.setLastModified(cached.lastModified() + 1),
Matchers.is(true)
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed a cached file timpestamp, because on some platforms these files have the same timestamp and the cached file isn't considered as valid

@vl4ds4m vl4ds4m requested a review from maxonfjvipon March 24, 2025 07:52
@vl4ds4m
Copy link
Contributor Author

vl4ds4m commented Mar 25, 2025

@maxonfjvipon please, take a look

Comment on lines 35 to 41
/**
* Hash directory for unphied files.
*/
@SuppressWarnings("PMD.ImmutableField")
@Parameter(property = "eo.hash")
private String hash = "";

Copy link
Member

Choose a reason for hiding this comment

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

@vl4ds4m it seems we have hash field in several mojos now, in ProbeMojo, in PullMojo and in UnphiMojo.
Let's make it only one by moving the field to the SafeMojo and make it protected so it'll look like:

abstract class SafeMojo {
  protected CommitHash hash = new ChConstant(
    new ChNarrow(new ChRemote(this.tag))
  );
}

I think when it's done - it'll require some tests fixes. We're almost good to merge

@vl4ds4m vl4ds4m requested a review from maxonfjvipon March 26, 2025 07:57
Copy link
Member

@maxonfjvipon maxonfjvipon left a comment

Choose a reason for hiding this comment

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

@vl4ds4m last change and we're good to merge

* If not set, will be computed from {@code tag} field.
* @checkstyle VisibilityModifierCheck (5 lines)
*/
protected CommitHash hash = new CommitHash.ChConstant(
Copy link
Member

Choose a reason for hiding this comment

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

@vl4ds4m let's use ChCached (caching decorator) instead of ChConst. This will allow not to call .value() explicitly on the next line, in the same way it's implemented in ProbeMojo

@vl4ds4m vl4ds4m requested a review from maxonfjvipon March 26, 2025 09:35
@maxonfjvipon
Copy link
Member

@yegor256 please check

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.

UnphiMojoTest.java:69-71: Remove @Disabled annotation on...
2 participants