Skip to content

Unify and speed opening of DirectoryGroup up - #9821

Open
jtulach wants to merge 1 commit into
apache:masterfrom
jtulach:jtulach/UnifyOpenSubprojects
Open

jtulach wants to merge 1 commit into
apache:masterfrom
jtulach:jtulach/UnifyOpenSubprojects

Conversation

@jtulach

@jtulach jtulach commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor
netbeans directory group
  • the trick is to find only "root projects" in the directory and leave the discovery of subprojects to OpenProjectList
  • speeding the subprojects discovery
    • via ProjectContainerProvider and SubprojectProvider up is also possible...
    • ... it is the most expensive part as it requires reading actual project files
    • ... but I leave it for another PR
  • this PR only improves the usability of Folder of Projects choice especially when opening root folder of NetBeans repository

checkShare = share != SharabilityQuery.Sharability.SHARABLE;
// don't need to check the sharability if the current folder is marked as recursively sharable

processFolderChildren(em, projects, h, counter, checkShare);

@jtulach jtulach Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  • this PR changes the behavior when a valid "root" Project is found
    • previously the scan continued inside of project structure
    • now it stops and relies on open subprojects behavior of OpenProjects.open
  • such a behavior is way faster
    • scanning NetBeans repository now takes just 4s
    • while previously it took 16s
  • the new behavior is more predictable
  • some Git repositories (like NetBeans or Maven) contain a lot of "testing projects" hidden in test data
    • the previous behavior found those projects ...
    • ... which was greatly unexpected ...
    • ... and also dangerous as those projects are often (intentionally) corrupted, misconfigured or otherwise broken
  • in case of NetBeans there was more than three hundred of such modules
  • lowering the number might even improve the Matthias warning a bit
    • although tons of time is then going to be spend while parsing the projects anyway ...
    • ... to be addressed in some future PR
  • the speed gain and the matched expectations are the major UX improvements of this PR

long then = System.currentTimeMillis();
Set<Project> newOpen = g != null ? g.getProjects(h, 10, 100) : Collections.emptySet();
long now = System.currentTimeMillis();
LOG.log(Level.FINE, "Found {0} projects of group {1} in {2} ms", new Object[] { newOpen.size(), g, now - then });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  • I am using netbeans -J-Dorg.netbeans.modules.project.ui.groups.Group.level=FINE to enabled this log message
  • and then grep Group nbbuild/testuserdir/var/log/messages.log for it
  • previously it would print Found 1 206 projects of group DirectoryGroup[id=netbeans,|projects|=1203] in 16 779 ms
  • now it prints Found 857 projects of group DirectoryGroup[id=netbeans,|projects|=857] in 3 665 ms

@jtulach jtulach changed the title Unify openning of subprojects Unify and speed opening of DirectoryGroup up Nov 22, 2026
assertEquals("Fresh empty group is opened", 0, backToNoGroup.length);
}

public void testDirectoryGroupFindsJustRootProjects() throws Exception {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@eppleton eppleton left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stopping the directory scan at root projects and letting OpenProjectList open the subprojects makes sense, and the speedup is impressive. I checked that OpenProjectList.open(..., openSubprojects=true) uses the same ProjectContainerProvider / SubprojectProvider logic as the removed visitSubprojects, so that part is equivalent. Some observations from tracing the code; I didn't build or run it.

Common root of the Group.java inline comment and the next point: Group.getProjects() used to include the subprojects and now returns only the roots, but Group.open and setMainProject still treat getProjects() as the full set of projects in the group.

setMainProject (not in the diff) keeps the main project only if getProjects().contains(mainProject). If the user picks a subproject as main project (e.g. a module of the master in a SubprojectsGroup, or a nested module in a DirectoryGroup), KEY_MAIN is now removed with a warning, so the main project is lost the next time the group is opened.

Also worth mentioning in the release notes: standalone projects nested inside another project but not declared as its subprojects (e.g. an examples/ folder not listed in the parent pom) are no longer found by a DirectoryGroup. I understand that's intended for test data, but it is a user-visible change.

The new test covers DirectoryGroup.findProjects; a test for switching between groups that share a root (see the Group.java comment) and for SubprojectsGroup would cover the rest.

}
}
}
projects.add(p);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The old code had if (p != null) here. projectForPath returns null when the master project folder was deleted or moved, so null now ends up in the set. With assertions enabled that trips assert !projects.contains(null) in Group.getProjects; without them, the null is passed on to opl.open.

//open the projects with current group
opl.open(toOpen.toArray(new Project[0]), false, false, h, null);
Project[] arrOpen = toOpen.toArray(new Project[0]);
opl.open(arrOpen, false, g != null && g.isSubprojects(), h, null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since newOpen now contains only the root projects, subprojects can get closed without being reopened. Example: group A is a SubprojectsGroup of X, so X and its subprojects are open. Switching to group B, a DirectoryGroup that also contains X, gives toClose = oldOpen - newOpen = the subprojects of X. X itself stays open, so it is not in toOpen, and openSubprojects never runs for it, so the subprojects stay closed. For the same reason the subprojects drop out of stayOpened, so their open documents are no longer persisted or restored per group.

if (!dir.isFolder()) {
return null;
}
if (checkShare) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

findProject is now inside the if (checkShare) block, so with checkShare == false no project would ever be found. The only caller passes true, so it works today, but it looks unintended. Also, the old code skipped further sharability queries below a folder that was SHARABLE; that optimization is gone. On the plus side, the new code queries dir, while the old one queried the parent fo by mistake.

@neilcsmith-net

Copy link
Copy Markdown
Member

I think we need to decide on #9736 #9737 and #9738 I'm in favour of @mbien approach which I believe removes this class entirely?

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.

3 participants