GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • java.evolved

This view

  • Original page
  • New address

GeezerVison is showing javaevolved.dev — Performance — java.evolved

Home / Topics / Performance
🏷 Performance 5 patterns

Topic: Performance

All Java patterns related to Performance — java.evolved

I/O

File memory mapping

Old try (FileChannel channel = FileChannel.open(path, StandardOpenOption.READ, StandardOpenOption.WRITE)) { MappedByteBuffer buffer = channel.map( FileChannel.MapMode.READ_WRITE, 0, (int) channel.size()); // Limited to 2GB // Freed by GC, no control }
Modern FileChannel channel = FileChannel.open(path, StandardOpenOption.READ, StandardOpenOption.WRITE); try (Arena arena = Arena.ofShared()) { MemorySegment segment = channel.map( FileChannel.MapMode.READ_WRITE, 0, channel.size(), arena); // No size limit // ... } // Deterministic cleanup
hover to see modern →
JDK 22+ learn more →
Tooling

JFR for profiling

Old // Install VisualVM / YourKit / JProfiler // Attach to running process // Configure sampling // Export and analyze // External tool required
Modern // Start with profiling enabled $ java -XX:StartFlightRecording= filename=rec.jfr MyApp // Or attach to running app: $ jcmd <pid> JFR.start
hover to see modern →
JDK 9+ learn more →
Tooling

Lazy stack inspection with StackWalker

Old StackTraceElement caller = Thread.currentThread() .getStackTrace()[2]; String callerClass = caller.getClassName();
Modern String callerClass = StackWalker.getInstance() .walk(frames -> frames.skip(1) .findFirst() .orElseThrow() .getClassName());
hover to see modern →
JDK 9+ learn more →
Tooling

Compact object headers

Old // Default: 128-bit object header // = 16 bytes overhead per object // A boolean field object = 32 bytes! // Mark word (64) + Klass pointer (64)
Modern // -XX:+UseCompactObjectHeaders // 64-bit object header // = 8 bytes overhead per object // 50% less header memory // More objects fit in cache
hover to see modern →
JDK 25+ learn more →
Tooling

AOT class preloading

Old // Every startup: // - Load 10,000+ classes // - Verify bytecode // - JIT compile hot paths // Startup: 2-5 seconds
Modern // Training run: $ java -XX:AOTCacheOutput=app.aot \ -cp app.jar com.App // Production: $ java -XX:AOTCache=app.aot \ -cp app.jar com.App
hover to see modern →
JDK 25+ learn more →
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.