Skip to content

Instantly share code, notes, and snippets.

View headius's full-sized avatar

Charles Oliver Nutter headius

View GitHub Profile

Comparing the run times for the most intensive job in our CI suite. JRuby 9.4 and 10 are both on Java 21 running equivalent settings. JRuby 10 can automatically utilize OpenJDK's AppCDS to improve startup time, and has many other optimizations for straight-line performance.

"Force JIT" here means JIT is enabled with a threshold of zero, causing nearly all methods and blocks to fully optimize and compile to JVM bytecode before running. JRuby 10 includes reductions in the overhead of the JIT and more are coming.

InvokeDynamic also can slow startup even as it improves execution performance. We have worked to reduce the overhead of InvokeDynamic use in JRuby while also utilizing it more effectively.

JRuby 9.4, force JIT, with full invokedynamic optimization.

Finished tests in 1053.596852s, 4.4125 tests/s, 1756.1271 assertions/s.
@headius
headius / aotcache.md
Last active February 13, 2025 14:38
Experimenting with JDK24 AOT caching and JRuby

Baseline startup

Base startup numbers with and without CDS (--nocache disables CDS), with and without --dev (simpler JVM JIT and no JRuby JIT)

[] jruby $ time jruby --nocache -e 1      
jruby --nocache -e 1  2.48s user 0.17s system 148% cpu 1.777 total
[] jruby $ time jruby --nocache -e 1
jruby --nocache -e 1  2.37s user 0.13s system 185% cpu 1.340 total
[] jruby $ time jruby --nocache -e 1
@headius
headius / macos on M1.md
Created January 11, 2025 09:01
JRuby startup tricks state of the art

JRuby without any flags

JRuby's startup without any flags is not unreasonable, but we're starting from a bad place.

jruby -e 1  2.57s user 0.17s system 166% cpu 1.648 total
[] jruby $ time jruby -e 1
jruby -e 1  2.46s user 0.13s system 183% cpu 1.407 total
[] jruby $ time jruby -e 1
jruby -e 1  2.48s user 0.13s system 179% cpu 1.455 total
@headius
headius / resources.md
Last active January 9, 2025 05:35
Resources for learning Java

These are resources suggested by my Java friends online.

Free online resources

  • W3Schools Java tutorial A nice high-level tutorial of basic Java features.
  • SAMS Teach Yourself Java There's multiple editions for different Java versions, so later editions may use features the robobrain doesn't support.
  • Modern Java Recommended by someone who used this to teach his kids.
@headius
headius / complexPowForSpecialAngle.java
Last active December 17, 2024 15:02
Comparison of C and Java versions of complex_pow_for_special_angle from CRuby
private IRubyObject complexPowForSpecialAngle(ThreadContext context, IRubyObject other) {
if (!(other instanceof RubyInteger integer)) {
return UNDEF;
}
IRubyObject x = UNDEF;
int dir;
if (f_zero_p(context, image)) {
x = real;
dir = 0;
@headius
headius / 1.bench_csv.txt
Last active December 10, 2024 23:31
Benchmarks of JRuby 10 on Corretto JDK 25 + GenShen
~/work/jruby $ ~/amazon-corretto-25.0.0.1.1-linux-x64/bin/java -version
openjdk version "25" 2024-12-10
OpenJDK Runtime Environment Corretto-25.0.0.1.1 (build 25+1-Nightly)
OpenJDK 64-Bit Server VM Corretto-25.0.0.1.1 (build 25+1-Nightly, mixed mode, sharing)
~/work/jruby $ JAVA_OPTS="-XX:+UseParallelGC" jruby bench/bench_csv.rb
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by org.jruby.util.StringSupport (file:/home/headius/work/jruby/lib/jruby.jar)
WARNING: Please consider reporting this to the maintainers of class org.jruby.util.StringSupport
WARNING: sun.misc.Unsafe::arrayBaseOffset will be removed in a future release
diff --git a/core/src/main/java/org/jruby/RubyClass.java b/core/src/main/java/org/jruby/RubyClass.java
index 1d6c3c631f..bd7314e387 100644
--- a/core/src/main/java/org/jruby/RubyClass.java
+++ b/core/src/main/java/org/jruby/RubyClass.java
@@ -53,6 +53,8 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
@headius
headius / .diff
Created October 17, 2024 21:46
proof of concept removing C parts of Json::Generator::State from Ruby json gem
diff --git a/java/src/json/ext/GeneratorState.java b/java/src/json/ext/GeneratorState.java
index 909f1a5..e3000b8 100644
--- a/java/src/json/ext/GeneratorState.java
+++ b/java/src/json/ext/GeneratorState.java
@@ -158,41 +158,6 @@ public class GeneratorState extends RubyObject {
return (GeneratorState)info.getSafeStatePrototype(context).dup();
}
- /**
- * <code>State#initialize(opts = {})</code>
@headius
headius / activerecord_jdbc_sqlit.diff
Created July 11, 2024 16:32
A diff of the ActiveRecord SQLite3 adapter and the same in ActiveRecord-JDBC-Adapter
--- ../rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb 2024-07-11 11:27:35
+++ ../activerecord-jdbc-adapter/lib/arjdbc/sqlite3/adapter.rb 2024-07-11 11:27:27
@@ -1,753 +1,884 @@
# frozen_string_literal: true
+ArJdbc.load_java_part :SQLite3
+
+require "arjdbc/abstract/core"
+require "arjdbc/abstract/database_statements"
+require 'arjdbc/abstract/statement_cache'
@headius
headius / gist:d3138efa52eed9c678414c8cfe08af27
Last active July 8, 2024 15:58
jruby + leyden cds + --dev flag crash
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x0000000104119800, pid=99782, tid=9475
#
# JRE version: OpenJDK Runtime Environment (24.0) (build 24-internal-adhoc.headius.jdk-iklam)
# Java VM: OpenJDK 64-Bit Server VM (24-internal-adhoc.headius.jdk-iklam, mixed mode, emulated-client, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, bsd-aarch64)
# Problematic frame:
# V [libjvm.dylib+0x2c9800] CompileBroker::compile_method(methodHandle const&, int, int, methodHandle const&, int, bool, CompileTask::CompileReason, JavaThread*)+0x94
#