Files
openide/platform/core-nio-fs
Vladimir Lagunov 2a3a00762d IJPL-157122 IJent WSL FS: classloader-aware instanceof in RoutingAwareFileSystemProvider
`MultiRoutingFsPath` is marked as package-private to prevent its creation in different classloaders.

The benchmark that proves that `instanceof` is much faster than a hash-table goes below. Even though it's obvious that `instanceof` is faster, the benchmark shows how much it is faster.

```java
@State(Scope.Benchmark)
public class InstanceofCacheBenchmark {
  private static final Map<Class<?>, Boolean> ourCache = Collections.synchronizedMap(new WeakHashMap<>());
  private final Object targetObject;

  public InstanceofCacheBenchmark() {
    targetObject = this;
    ourCache.put(getClass(), true);
  }

  @Benchmark
  public void measureInstanceof() {
    boolean ignored = targetObject instanceof InstanceofCacheBenchmark;
  }

  @Benchmark
  public void measureCache() {
    boolean ignored = ourCache.get(targetObject.getClass());
  }

  public static void main(String[] args) throws RunnerException {
    Options opt = new OptionsBuilder()
      .include(InstanceofCacheBenchmark.class.getSimpleName())
      .threads(1)
      .forks(0)
      .build();

    new Runner(opt).run();
  }
}
```

On i9-12900 on Windows 11:

```
Benchmark                                    Mode  Cnt           Score            Error  Units
InstanceofCacheBenchmark.measureCache       thrpt    5    64987581.855 ±     111715.045  ops/s
InstanceofCacheBenchmark.measureInstanceof  thrpt    5  2575306704.170 ± 1054801816.988  ops/s
```

GitOrigin-RevId: 2268e02a3e92bdb6dec8fc81efce8585a5eef2fd
2024-07-04 16:07:08 +00:00
..