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

[IDE] Slow Startup - BaseNoGui.onBoardOrPortChange trigger two rescanLibraries() #10228

Closed
ricardojlrufino opened this issue May 17, 2020 · 7 comments · Fixed by #10270
Closed
Labels

Comments

@ricardojlrufino
Copy link
Contributor

I noticed that the method is being called 2 twice:
librariesIndexer.rescanLibraries ()

image

I believe this is a bug, because the librariesIndexer.setArchitecturePriority, seems to have no influence on the process.

This makes the other issue (#10214) I found a little worse

@matthijskooijman
Copy link
Collaborator

matthijskooijman commented May 18, 2020

I believe this is a bug, because the librariesIndexer.setArchitecturePriority, seems to have no influence on the process.

But isn't this fixed by calling rescanLibraries the second time? Maybe that's why it is called the second time at all?

Scanning twice is of course a performance problem to be fixed. Without looking at the code in detail, I would think that maybe setLibrariesFolders should just not call rescanLibraries()? It seems that the two places that call setLibrariesFolders now also call rescalLibraries, so just removing the first call would be ok?

@cmaglie
Copy link
Member

cmaglie commented May 18, 2020

After looking at the call tree of setLibrariesFolder, the following places setLibrariesFolder is followed by rescanLibraries:

indexer.setLibrariesFolders(BaseNoGui.getLibrariesFolders());
indexer.rescanLibraries();

// Scan for libraries in each library folder.
// Libraries located in the latest folders on the list can override
// other libraries with the same name.
librariesIndexer.setLibrariesFolders(librariesFolders);
if (getTargetPlatform() != null) {
librariesIndexer.setArchitecturePriority(getTargetPlatform().getId());
}
librariesIndexer.rescanLibraries();

indexer.setLibrariesFolders(folders);
indexer.rescanLibraries();

indexer.setLibrariesFolders(folders);
indexer.rescanLibraries();


Instead in the following places the "autoreload" feature is actually used:

folders.add(new UserLibraryFolder(SD121, Location.SKETCHBOOK));
indexer.setLibrariesFolders(folders);

folders.add(new UserLibraryFolder(Bridge170, Location.SKETCHBOOK));
indexer.setLibrariesFolders(folders);


@ricardojlrufino
if you add a call to rescanLibraries in the two cases above, I think you can safely remove the rescanLibraries call from setLibrariesFolder. Nice catch, if you want to open a PR this can be quickly merged.

@matthijskooijman
Copy link
Collaborator

Instead in the following places the "autoreload" feature is actually used:

Ah, I had not looked at the tests in my analysis above, good call. But indeed, just calling rescalLibraries in the tests seems fine :-)

@ricardojlrufino
Copy link
Contributor Author

to have something cleaner, what about adding a second boolean parameter to setLibrariesFolders
like : indexer.setLibrariesFolders(File files, boolean rescan);
what do you think ?

@ricardojlrufino
Copy link
Contributor Author

image

@matthijskooijman
Copy link
Collaborator

That would also be ok (though boolean parameters have the risk of becoming unclear if you don't add a comment in the call), but I'm not so sure it would be needed if rescanLibraries is called always anyway (ignoring the tests). OTOH, in one of the two places in the code, rescanLibraries is called directly after setLibrariesFolders, so that could be shortened to pass true instead).

Still, I'm not sure. On one hand, it might be good to somewhat ensure that rescan happens when changing the library folder. OTOH, explicitly calling rescanLibraries() might result in code that is easier to read (clearer what is going on).

One other alternative would be to have a setLibrariesFolderAndRescan() function, which would be easier to read that a true argument.

@cmaglie
Copy link
Member

cmaglie commented May 19, 2020

I agree, we already have made some API in the IDE in the past using boolean that lead to methods like doSomething(true, false, false). That looks very bad in retrospecitve.

@ricardojlrufino I'd follow Matthijs suggestion and do:

  • add rescanLibraries() where it's missing and remove it from setLibrariesFolder()

or

  • add setLibrariesFolderAndRescan() and remove rescan from setLibrariesFolder()

up to you, both looks OK to me.

ricardojlrufino added a commit to ricardojlrufino/Arduino that referenced this issue May 21, 2020
ricardojlrufino added a commit to ricardojlrufino/Arduino that referenced this issue May 21, 2020
cmaglie pushed a commit to cmaglie/Arduino that referenced this issue May 25, 2020
cmaglie pushed a commit to cmaglie/Arduino that referenced this issue May 25, 2020
@cmaglie cmaglie added this to the Release 1.8.13 milestone May 25, 2020
cmaglie pushed a commit to cmaglie/Arduino that referenced this issue May 25, 2020
Previously rescanLibraries() was automatically called internally in
setLibrariesFolder(). This lead to double calls to rescanLibraries()
when setLibrariesFolder() was used in combination with an explicit
call to rescanLibraries().

This commit adds a new method setLibrariesFoldersAndRescan(..) and
removes the internal call to rescanLibraries() from setLibrariesFolder().

The existing setLibrariesFolder()+rescanLibraries() combos have been
replaced with setLibrariesFoldersAndRescan().

Fix arduino#10228
cmaglie pushed a commit that referenced this issue May 25, 2020
Previously rescanLibraries() was automatically called internally in
setLibrariesFolder(). This lead to double calls to rescanLibraries()
when setLibrariesFolder() was used in combination with an explicit
call to rescanLibraries().

This commit adds a new method setLibrariesFoldersAndRescan(..) and
removes the internal call to rescanLibraries() from setLibrariesFolder().

The existing setLibrariesFolder()+rescanLibraries() combos have been
replaced with setLibrariesFoldersAndRescan().

Fix #10228
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants