Skip to content

I20240722-1800

@HannesWell HannesWell tagged this 22 Jul 20:44
Replace the 'DosHandler' by the new 'Win32Handler' that calls the
native Windows method 'FindFirstFileW() via to read file-info and
'SetFileAttributesW()' to set file attributes, similar to the JNI based
'LocalFileHandler', but only uses JNA to perform native calls.

In the DosHandler calling 'Path.toRealPath()' is a very expensive
operation on Windows because for each segment of the path the actual
name on the file-system is looked up (the Windows FS is
case-insensitive). In a Windows JDK this is implemented by calling the
native Windows function 'FindFirstFileW()' for each segment of path.
Because we are just interested in the last segment's name, i.e. the
filename, all calls except for the last segment are unnecessary.

With this change the 'DosHandler' is replaced by the optimized
'Win32Handler' that calls 'FindFirstFileW()' only once for the last
segment of the path and to read all file-infos from the passed
'WIN32_FIND_DATAW' structure. Depending on the length of the path, this
speeds up DosHandler.fetchFileInfo() between multiple factors up to a
magnitude.

Furthermore 'putFileInfo()' is optimized by replacing the code that
formerly set file-attributes through a java.nio DosFileAttributeView by
a single native call (through JNA) to 'GetFileAttributesW()' and
'SetFileAttributesW()'. The latter is only called if applying all
attribute values to set changes the current values. Using the
'DosFileAttributeView' works similar, but reads and write the
file-attributes individually for each attribute value that is set (at
the moment three are set). Consequently the runtime of 'putFileInfo()'
should be reduced by  a factor of about three.

The new implementation considers the behavior of the previous
java.nio.file based implementation but also considers the current
native/JNI implementation of 'LocalFileNatives'.
It intended to have all the capabilities of the native/JNI
implementation and its logic is based on that but performs all native
calls through JNA.
Assets 2
Loading