Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 268026 - Performance issue in BaseFileObj.getPath --> FileName.getName
Performance issue in BaseFileObj.getPath --> FileName.getName
Status: NEW
Product: ide
Classification: Unclassified
Component: Performance
Dev
PC Windows 7
: P3 (vote)
: TBD
Assigned To: Tomas Hurka
issues@performance
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2016-09-14 15:40 UTC by NukemBy
Modified: 2016-09-14 15:40 UTC (History)
0 users

See Also:
Issue Type: DEFECT
:


Attachments
BaseFileObj.getPath --> FileName.getName (47.13 KB, image/jpeg)
2016-09-14 15:40 UTC, NukemBy
Details

Note You need to log in before you can comment on or make changes to this bug.
Description NukemBy 2016-09-14 15:40:10 UTC
Created attachment 162049 [details]
BaseFileObj.getPath --> FileName.getName

Please take a look onto attached screenshot of selfprofiler.

I see there is strange collaboration between BaseFileObj & FileName classes.

FileName actually stores the name as some CharSequence and each call to fileNaming.getName() results in call to CharSequence.toString(), so ... building a path of 10 elements in BaseFileObj.getPath() is actaully construction of 10 new Strings plus 10 invocations of toString(). This is pressure on both CPU and GC.

It may happen that someone wanted to implement FileNaming.appendNameTo(StringBuilder pathName), but it is not.

Anyway - current implementation is very performance unfriendly.

Below is the source code for reference

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

public class FileName implements FileNaming {

    protected FileName(final FileNaming parent, final File file, Integer theKey) {
        this.parent = parent;
        this.name = CharSequences.create(parseName(parent, file));
        this.currentName = name;

    public @Override final String getName() {
        return currentName.toString();
    }


public abstract class BaseFileObj extends FileObject {

    @Override
    public final String getPath() {
        FileNaming fileNaming = getFileName();
        Deque<String> stack = new ArrayDeque<String>();
        while (fileNaming != null) {
            stack.addFirst(fileNaming.getName());
            fileNaming = fileNaming.getParent();
        }
        String rootName = stack.removeFirst();
        if (BaseUtilities.isWindows()) {
            rootName = rootName.replace(File.separatorChar, '/');
            if(rootName.startsWith("//")) {  //NOI18N
                // UNC root like //computer/sharedFolder
                rootName += "/";  //NOI18N
            }
        }
        StringBuilder path = new StringBuilder();
        path.append(rootName);
        while (!stack.isEmpty()) {
            path.append(stack.removeFirst());
            if (!stack.isEmpty()) {
                path.append('/');  //NOI18N
            }
        }
        return path.toString();
    }


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo