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

Restore speed improvements #79

Merged
merged 6 commits into from
Jun 23, 2022

Conversation

gnodet
Copy link
Member

@gnodet gnodet commented May 2, 2022

No description provided.

@gnodet
Copy link
Member Author

gnodet commented May 17, 2022

@plamentotev would you mind having a quick look ?

@plamentotev
Copy link
Member

@plamentotev would you mind having a quick look ?

I'll try to check it later this week or the beginning of the next. But I'm not completely sure what caused the original issue. And I wonder if there is simpler solution that keeping tract of the target using nested resource.

@@ -21,7 +21,7 @@ public void testRealSymlink()
final File file = new File( "src/test/resources/symlinks/src/symDir" );
PlexusIoResourceAttributes attrs = FileAttributes.uncached( file );
assertTrue( attrs.isSymbolicLink() );
PlexusIoFileResource r = new PlexusIoFileResource( file, "symDir", attrs );
Copy link
Member

Choose a reason for hiding this comment

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

If my understanding is correct this change does not keep the current behavior of PlexusIoFileResource. If this is the case it should be a separate change (possibly requiring major version update if it is breaking change) as it is not just performance improvement.

Copy link
Member Author

Choose a reason for hiding this comment

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

I disagree. The PlexusIoFileResource has no public constructor, so the only way it can be created is through ResourceFactory.createResource or other internal methods.
What happens is that I think this change restores the original idea : PlexusIoSymlinkResource instances are used to represent symlinks and PlexusIoFileResource for regular files.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with the initial commit, is that I missed the fact that attributes are handled in a very specific (and not necessarily intuitive way) for links : some attributes are retrieved from the link and some others from the target.
That's the reason why I've introduced the getLink() and getTarget() methods on the PlexusIoSymlinkResource which return PlexusIoResource instances that will more explicitly handle the link and the target.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation. Now it makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

It would be nice if you can add some comments as for why getLink and getTarget are there to make it more clearer.

/**
* @deprecated use {@link #FileAttributes(File)} and remove the unused userCache and groupCache parameters
*/
@Deprecated
public FileAttributes( @Nonnull File file, @Nonnull Map<Integer, String> userCache,
Copy link

Choose a reason for hiding this comment

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

InlineMeSuggester: This deprecated API looks inlineable. If you'd like the body of the API to be inlined to its callers, please annotate it with @InlineMe.

Suggested change
public FileAttributes( @Nonnull File file, @Nonnull Map<Integer, String> userCache,
@InlineMe(replacement = "this(file)")

(at-me in a reply with help or ignore)


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

@michael-o michael-o self-requested a review May 29, 2022 21:49
gnodet added 5 commits May 30, 2022 18:05
The PlexusIoFileResource constructor calls file.lastModified(), file.length(), file.isFile(), file.isDirectory() and file.exists() which is very inefficient
@gnodet gnodet force-pushed the restore-speed-improvements branch from 139a7e7 to 46245e4 Compare May 30, 2022 16:07
@gnodet
Copy link
Member Author

gnodet commented May 30, 2022

I've pushed another commit which removes another set of file attributes access. We should be down to 2 calls per file, one with the follow links options and one without.


public class PlexusIoSymlinkResource
extends PlexusIoFileResource
implements SymlinkDestinationSupplier
{
private final File symnlinkDestination;
private final String symLinkDestination;
Copy link

Choose a reason for hiding this comment

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

UnusedVariable: The field 'symLinkDestination' is never read.

(at-me in a reply with help or ignore)


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

@@ -39,6 +40,10 @@
public class FileAttributes
implements PlexusIoResourceAttributes
{
public static final LinkOption[] FOLLOW_LINK_OPTIONS = new LinkOption[] { };

public static final LinkOption[] NOFOLLOW_LINK_OPTIONS = new LinkOption[] { LinkOption.NOFOLLOW_LINKS };
Copy link

Choose a reason for hiding this comment

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

MutablePublicArray: Non-empty arrays are mutable, so this public static final array is not a constant and can be modified by clients of this class. Prefer an ImmutableList, or provide an accessor method that returns a defensive copy.

(at-me in a reply with help or ignore)


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

@cstamas
Copy link
Member

cstamas commented Jun 22, 2022

Just a note: would be good if this PR goes in BEFORE this one #84 as it will most probably conflict (let me handle it) and it also removes Plexus completely, hence no more Junit3 tests as well...

@michael-o michael-o self-requested a review June 23, 2022 07:56
Copy link
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

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

LGTM. Squash, merge and move on.

@cstamas cstamas merged commit 6ffc902 into codehaus-plexus:master Jun 23, 2022
@wilx
Copy link

wilx commented Sep 15, 2022

I suspect this has caused https://issues.apache.org/jira/projects/MASSEMBLY/issues/MASSEMBLY-965. See also #89.

for ( String name : resources )
{
String sourceDir = name.replace( '\\', '/' );
File f = new File( dir, sourceDir );

PlexusIoResourceAttributes attrs = new FileAttributes( f, cache1, cache2 );
attrs = mergeAttributes( attrs, f.isDirectory() );
FileAttributes fattrs = new FileAttributes( f );

Choose a reason for hiding this comment

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

This usage without the caches is now quite expensive and likely causing a performance regression reported in #109

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.

7 participants