Skip to content

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

Closed
@ricardojlrufino

Description

@ricardojlrufino

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

Activity

matthijskooijman

matthijskooijman commented on May 18, 2020

@matthijskooijman
Collaborator

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

cmaglie commented on May 18, 2020

@cmaglie
Member

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

matthijskooijman commented on May 18, 2020

@matthijskooijman
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

ricardojlrufino commented on May 18, 2020

@ricardojlrufino
ContributorAuthor

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

ricardojlrufino commented on May 18, 2020

@ricardojlrufino
ContributorAuthor

image

matthijskooijman

matthijskooijman commented on May 19, 2020

@matthijskooijman
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

cmaglie commented on May 19, 2020

@cmaglie
Member

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.

5 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      [IDE] Slow Startup - BaseNoGui.onBoardOrPortChange trigger two rescanLibraries() · Issue #10228 · arduino/Arduino