Skip to content

Introduce faster file refresh on Linux (x86_64 only for now) - #2793

Merged
iloveeclipse merged 2 commits into
eclipse-platform:masterfrom
iloveeclipse:Linux86_64_fast
Jul 3, 2026
Merged

iloveeclipse merged 2 commits into
eclipse-platform:masterfrom
iloveeclipse:Linux86_64_fast

Conversation

@iloveeclipse

@iloveeclipse iloveeclipse commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

The code is supposed to speed up NFS file access on Linux by an order of magnitude by fetching directory children data (IFileInfo) in one shot from JNI (via array of StructStat).

LocalFile.childInfos(int, IProgressMonitor) overrides now the FileStore.childInfos(int, IProgressMonitor) and calls (on Linux) LinuxFileHandler.listDirectoryAndGetFileInfos() which forwards to faster native implementation in
LinuxFileNatives.listDirectoryAndGetFileInfos().

  • Introduced new libfastlinuxfile_1_0_0 library for x86_64 Linux architecture (which can be also built on other Linux architectures).
  • Created dedicated Linux specific package org.eclipse.core.internal.filesystem.local.linux
  • removed Mac code paths from new code to simplify Linux port
  • Added system property to disable new binary if needed via -Declipse.filesystem.useFastLinuxNatives=false.
  • With the flag above, the behavior on Linux should be unchanged compared with the previous code state.
  • In next release we can try to remove native code and use FFM API if we will allow the bundle to use Java 25.
  • As of today, FFM use is not possible - multi-release based bundle attempt failed due missing PDE / Equinox support for debugging MR code (see Support debugging multi-release bundles eclipse-pde/eclipse.pde#2391).
Variant NFS (ms) Local (ms)
Original code 70000 - 90000 900 - 2500
Updated code 800 - 5500 800 - 2500

I've measured data with the extra patch to trace the refresh data from Eclipse : #2792 on RHEL 9.6.

To drop local FS caches, I've used sync && echo 3 | sudo tee /proc/sys/vm/drop_caches .

Unfortunately this doesn't drop NFS server file caches, but interestingly, I couldn't see any caching effect on the NFS results for the old code anyway. Only new code is affected by the NFS server cache and produces sometimes NFS times comparable to the local FS performance.

Script below was used to create test directory structure with 50 folders a 5000 files each (250.000 files) used for performance tests above. Just create shell script and run it inside a project.

#!/bin/bash

TOTAL_FILES=250000
FILES_PER_DIR=5000
BASE_DIR="testdata"

mkdir -p "$BASE_DIR"

NUM_DIRS=$(( (TOTAL_FILES + FILES_PER_DIR - 1) / FILES_PER_DIR ))

for ((d=1; d<=NUM_DIRS; d++)); do
(
    dir="$BASE_DIR/dir_$(printf "%03d" $d)"
    mkdir -p "$dir"

    start=$(( (d-1)*FILES_PER_DIR + 1 ))
    end=$(( d*FILES_PER_DIR ))
    [ $end -gt $TOTAL_FILES ] && end=$TOTAL_FILES

    for ((i=start; i<=end; i++)); do
        : > "$dir/file_$(printf "%06d" $i).dat"
    done
) &
done

wait
echo "Done"

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a Linux x86_64–specific “fast” native path for directory listing + bulk IFileInfo retrieval to significantly speed up refresh/file access on NFS, with a system property to disable the fast natives and fall back to the existing behavior.

Changes:

  • Add a new Linux-specific native implementation (fastlinuxfile_1_0_0) and corresponding Java JNI layer to fetch directory entries + file infos in one call.
  • Update native handler selection to prefer the fast Linux path on Linux x86_64 (configurable via eclipse.filesystem.useFastLinuxNatives).
  • Extend performance benchmarks and bump test/fragment versions to reflect the new functionality.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/perf/BenchFileStore.java Adds Linux-fast-native benchmark variants (needs platform guarding).
resources/tests/org.eclipse.core.tests.resources/pom.xml Version bump for test bundle.
resources/tests/org.eclipse.core.tests.resources/META-INF/MANIFEST.MF Version bump for test bundle.
resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/UnixFileNatives.java Refactors constant usage to static imports; no functional change intended.
resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/StructStat.java Simplifies StructStat fields and toFileInfo() for the Unix native path.
resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFileNativesManager.java Adds fast-Linux-native selection + new disable property; routes to Linux handler on Linux x86_64.
resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/linux/LinuxStructStat.java New Linux-only stat struct mirror used for bulk directory listing JNI.
resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/linux/LinuxFileNatives.java New JNI wrapper that loads fastlinuxfile_1_0_0 and exposes bulk listing + stat operations.
resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/linux/LinuxFileHandler.java New NativeHandler implementation delegating to LinuxFileNatives.
resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/linux/LinuxFileFlags.java New Linux flag resolver populated via JNI getFlag.
resources/bundles/org.eclipse.core.filesystem/natives/unix/fastlinux/Makefile Build script for the fast Linux native library (install target path is currently incorrect).
resources/bundles/org.eclipse.core.filesystem/natives/unix/fastlinux/fastlinuxfile.h JNI header and helper prototypes for the fast Linux native library.
resources/bundles/org.eclipse.core.filesystem/natives/unix/fastlinux/fastlinuxfile.c Native implementation for fast directory enumeration + bulk stat collection.
resources/bundles/org.eclipse.core.filesystem.linux.x86_64/pom.xml Builds and packages the new fast Linux native library into the x86_64 fragment.
resources/bundles/org.eclipse.core.filesystem.linux.x86_64/META-INF/MANIFEST.MF Version bump and updated host-version range for the fragment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

    54 files  ±0      54 suites  ±0   56m 19s ⏱️ - 3m 11s
 4 680 tests ±0   4 658 ✅ ±0   22 💤 ±0  0 ❌ ±0 
11 934 runs  ±0  11 781 ✅ ±0  153 💤 ±0  0 ❌ ±0 

Results for commit 8f4ede3. ± Comparison against base commit 6bef442.

♻️ This comment has been updated with latest results.

The code is supposed to speed up NFS file access on Linux by an order of
magnitude by fetching directory children data (IFileInfo) in one shot
from JNI (via array of StructStat).

LocalFile.childInfos(int, IProgressMonitor) overrides now the
FileStore.childInfos(int, IProgressMonitor) and calls (on Linux)
LinuxFileHandler.listDirectoryAndGetFileInfos() which forwards to faster
native implementation in
LinuxFileNatives.listDirectoryAndGetFileInfos().

- Introduced new libfastlinuxfile_1_0_0 library for x86_64 Linux
architecture (which can be also built on other Linux architectures).
- Created dedicated Linux specific package
org.eclipse.core.internal.filesystem.local.linux
- removed Mac code paths from new code to simplify Linux port
- Added system property to disable new binary if needed via
"-Declipse.filesystem.useFastLinuxNatives=false"

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.

@iloveeclipse
iloveeclipse merged commit e777932 into eclipse-platform:master Jul 3, 2026
18 checks passed
@iloveeclipse
iloveeclipse deleted the Linux86_64_fast branch July 3, 2026 10:29
iloveeclipse added a commit to iloveeclipse/www.eclipse.org-eclipse that referenced this pull request Jul 14, 2026
iloveeclipse added a commit to iloveeclipse/www.eclipse.org-eclipse that referenced this pull request Jul 15, 2026
iloveeclipse added a commit to eclipse-platform/www.eclipse.org-eclipse that referenced this pull request Jul 15, 2026
Comment on lines +271 to +385
JNIEXPORT jobjectArray JNICALL Java_org_eclipse_core_internal_filesystem_local_linux_LinuxFileNatives_listDir
(JNIEnv *env, jclass, jbyteArray path)
{
char *name;
DIR *dir = NULL;
jsize arrayLength;
int count = 0;
int i;
struct dirent *entry;
jobjectArray namesArray;
jobjectArray resultStatsArray = NULL;
jobjectArray result = NULL;
jclass byteArrayClass;

byteArrayClass = (*env)->FindClass(env, "[B");
if (byteArrayClass == NULL) {
return NULL;
}
namesArray = (*env)->NewObjectArray(env, INITIAL_LIST_ARRAY_SIZE, byteArrayClass, NULL);
if (namesArray == NULL) {
return NULL;
}
arrayLength = INITIAL_LIST_ARRAY_SIZE;

name = (char*) getByteArray(env, path);
if (name == NULL) {
goto cleanup;
}
dir = opendir(name);
free(name);
if (dir == NULL) {
goto cleanup;
}
while ((entry = readdir(dir)) != NULL) {
jbyteArray nameBytes;
jsize nameLen;
jobjectArray grownArray;

/* Skip . and .. */
if (entry->d_name[0] == '.' &&
(entry->d_name[1] == '\0' ||
(entry->d_name[1] == '.' && entry->d_name[2] == '\0'))) {
continue;
}

if (count >= arrayLength) {
jsize newLength = arrayLength > 0 ? arrayLength * 2 : 1;

if (newLength < arrayLength) {
goto cleanup;
}

grownArray = (*env)->NewObjectArray(env, newLength, byteArrayClass, NULL);
if (grownArray == NULL) {
goto cleanup;
}

if (copyObjectArray(env, namesArray, grownArray, arrayLength) != 0) {
(*env)->DeleteLocalRef(env, grownArray);
goto cleanup;
}

(*env)->DeleteLocalRef(env, namesArray);
namesArray = grownArray;
arrayLength = newLength;
}

/* Add the directory entry name as raw bytes to the names array */
nameLen = (jsize)strlen(entry->d_name);
nameBytes = (*env)->NewByteArray(env, nameLen);
if (nameBytes == NULL) {
goto cleanup;
}
(*env)->SetByteArrayRegion(env, nameBytes, 0, nameLen, (const jbyte*)entry->d_name);
(*env)->SetObjectArrayElement(env, namesArray, count, nameBytes);
(*env)->DeleteLocalRef(env, nameBytes);
if ((*env)->ExceptionCheck(env)) {
goto cleanup;
}

count++;
}

resultStatsArray = (*env)->NewObjectArray(env, count, byteArrayClass, NULL);
if (resultStatsArray == NULL) {
goto cleanup;
}

for (i = 0; i < count; i++) {
jobject existingName = (*env)->GetObjectArrayElement(env, namesArray, i);
if ((*env)->ExceptionCheck(env)) {
goto cleanup;
}
(*env)->SetObjectArrayElement(env, resultStatsArray, i, existingName);
(*env)->DeleteLocalRef(env, existingName);
if ((*env)->ExceptionCheck(env)) {
goto cleanup;
}
}

result = resultStatsArray;
resultStatsArray = NULL;

cleanup:
if (dir != NULL) {
closedir(dir);
}
if (namesArray != NULL) {
(*env)->DeleteLocalRef(env, namesArray);
}
if (resultStatsArray != NULL) {
(*env)->DeleteLocalRef(env, resultStatsArray);
}
return result;
}

@HannesWell HannesWell Sep 19, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's too late for this PR, but I wonder if there is a real benefit in a native implementation of NativeHandler.listDirectoryNames(String) since the native implementation in the JDK of File.list() looks very similar to me:
https://github.com/openjdk/jdk/blob/6c48f4ed707bf0b15f9b6098de30db8aae6fa40f/src/java.base/unix/native/libjava/UnixFileSystem_md.c#L296-L358

But I'm not a native Linux expert and might have oversaw important details.

Maybe the benefit of this change is just in listDirectoryAndGetFileInfos() and listDirectoryNames() could just use the default Java implementation calling File.list()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@iloveeclipse could you have a look at the previous questions? Thanks in advance.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sorry, no time, we have internal release and must fix lot of issues before code freeze before Friday.

@HannesWell HannesWell Sep 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No problem. I don't think we're in a rush.

In the meantime I asked Copilot (it used Claude Sonnet 5) and it confirmed that only listDirectoryAndGetFileInfos() can have a significant gain on non-local file-systems.
But of course that answer can also be wrong, so if can check and if necessary follow-up on that, when you have time, that would be great.

Prompt

Check the PR @eclipse-platform/eclipse.platform/pull/2793 and explain why that native implementation is more performant than using existing Java APIs available in Java-25?
Additionally check which parts could be implement with existing Java APIs, preferable NIO, with comparable performance and which parts of the native implementation are significantly faster and should for example be ported to use the FFM API.
Mixing Java NIO and FFM native calls where suitable to get the maximal performance is fine.

Copilot response

Why the native implementation is faster

The performance win described in the PR (70,000–90,000 ms → 800–5,500 ms for 250,000 files over NFS) is not primarily about native code being "faster CPU-wise" than Java — it's about eliminating round-trips per file. That's the key architectural insight:

The old path (still what plain Java NIO/java.io does today):
For each file in a directory, Eclipse's resource refresh does the equivalent of:

  1. File.list() / Files.newDirectoryStream() → one syscall sequence to enumerate names
  2. For each entry: a separate stat/lstat call (via File.exists(), isDirectory(), lastModified(), etc., or Files.readAttributes())

On local disks this is cheap because the metadata is cached in the local page cache/dentry cache. On NFS, every stat call is (or can be) a network round-trip to the NFS server. With 5,000 files per directory, that's 5,000 sequential round-trips — even at 1–2ms latency each, that's 5–10 seconds per directory, and it compounds across all directories, matching the observed 70–90 seconds for 250k files.

The new native path (listDirAndGetFileInfos in fastlinuxfile.c):

  • Opens the directory once (opendir/dirfd)
  • Uses readdir() to enumerate entries and, for each entry, immediately calls fstatat(directoryFd, entry->d_name, ...) relative to the already-open directory file descriptor, in the same JNI call, in a single tight loop, without returning to Java between each entry.
  • Returns the entire batch of LinuxStructStat objects to Java in one JNI array transfer, instead of one JNI call per file.

The speedup comes from three combined effects:

  1. Batching stat calls into one JNI invocation — avoids per-file JNI transition overhead (which is small but adds up at 5,000+ calls) and, more importantly, avoids Eclipse's higher-level code making one Java method call → one native call → one syscall per file.
  2. Using fstatat(dirfd, name, ...) instead of stat(path) — resolves relative to an already-open directory descriptor rather than re-walking/re-resolving the full path from the root for every single file. On NFS this can avoid redundant lookup/attribute-cache revalidation per call.
  3. Because it's all in one native call, the NFS client can benefit from readahead/caching behavior within that single burst of syscalls in ways that don't happen when Java-level code does one stat per iteration with intervening Java work (which is exactly what the PR author observed: the NFS server cache only kicked in for the new code, never for the old code).

This is fundamentally a "vectorize/batch the syscalls" optimization, not something achievable by just calling equivalent single-file NIO APIs — Files.readAttributes() is still one syscall per file with no batching primitive in java.nio.

What HannesWell pointed out in review

Reviewer HannesWell raised exactly the right question inline (comment on fastlinuxfile.c):

"I wonder if there is a real benefit in a native implementation of NativeHandler.listDirectoryNames(String) since the native implementation in the JDK of File.list() looks very similar... Maybe the benefit of this change is just in listDirectoryAndGetFileInfos() and listDirectoryNames() could just use the default Java implementation calling File.list()?"

iloveeclipse did not respond substantively (only noted lack of time before a release freeze), so this was never resolved in the PR.

Breakdown: what can use plain NIO vs. what needs FFM/native

Native function Purpose Can use existing Java API with comparable perf? Recommendation
listDir() / listDirectoryNames() Just enumerate directory entry names Yes — File.list() / Files.newDirectoryStream(Path) already do a single opendir/readdir loop internally in the JDK's native UnixFileSystem_md.c. No batching benefit here since no per-entry stat is done. Replace with Files.list()/File.list(). Matches HannesWell's review comment exactly — no native code needed.
stat() / lstat() (single file) Get metadata for one path Yes — Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS) provides st_mode/size/mtime equivalents. Use NIO PosixFileAttributes; no measurable difference for single-file calls.
readlink() Read symlink target Yes — Files.readSymbolicLink(Path). Use NIO.
chmod() Set POSIX permissions Yes — Files.setPosixFilePermissions(Path, Set<PosixFilePermission>). Use NIO.
listDirAndGetFileInfos() (the batched directory+stat combo) Enumerate directory and stat every entry via one dirfd-relative loop, returned as one batch No — there is no NIO/FFM equivalent of "give me a directory listing with per-entry fstatat already resolved in a single native call." Files.newDirectoryStream + per-entry readAttributes() reintroduces the N round-trips problem this PR exists to solve. This is the one piece that legitimately justifies a native/FFM implementation. It should be the target for a Java 25 FFM (Foreign Function & Memory API) port: use Linker/SymbolLookup to bind directly to opendir, readdir, dirfd, fstatat, and lay out struct dirent/struct stat with MemoryLayout, batching the whole loop in Java-side FFM code without needing a compiled .so (eliminates the Makefile/native-build/architecture-packaging problems entirely — which is the current PR's actual complexity: a custom C library, JNI headers, per-arch fragments, a Makefile with a bug the reviewer already flagged pointing at the wrong 32-bit output path).

Bottom line: the described speedup is real and architecturally sound (batching stat calls under NFS latency), but it applies specifically to listDirAndGetFileInfos, not to the whole native surface added in this PR. listDirectoryNames/stat/lstat/readlink/chmod are unlikely to be meaningfully faster than JDK's own native implementations and add native-library maintenance burden (build system, x86_64-only packaging, the Makefile path bug flagged in review) for no real gain. A good "mixed NIO + FFM" design would drop the JNI library entirely and use plain NIO for the single-file operations, keeping only a small FFM-based readdir+fstatat batching routine for the directory-refresh hot path — which also solves the PR's stated goal of eventually removing native code once FFM/PDE debugging support (referenced in the PR body, blocked on eclipse-pde/eclipse.pde#2391) becomes viable.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants