Reduce scan time by avoid having redundant file access by attilapuskas · Pull Request #850 · classgraph/classgraph (original) (raw)

added 9 commits

April 17, 2024 14:32

Even though the Files API might be considered as a newer variant, but for example on Windows systems certain methods are four times slower than the File counterparts.

Both FileSlice & PathSlice do the same, so no need for this additional check.

Probably it was there only to set the open state to true, so that the close works as intended.

The file attributes are already used when creating a new Resource so we can easily pass it to the Resource for further usage, thus can share the already loaded data for a Path.

If from a subPath it turns out to be a file, then we do not need to check at the end whether it's a directory so we now remove the files from the pathsInDir.

The previous commits introduced some code that would not work on JRE 7, which are fixed here.

Flip the condition check to first check the fileName since it is cheaper and also use the built-in filtering. The latter does not really contribute to the performance benefit though.

ClasspathElementDir already checks whether the resource can be accessed and is a file before creating it. So, in order to avoid the redundant file access we do not check the same in PathSlice created via these Resources.

szarnekow

szarnekow

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})