Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View headius's full-sized avatar

Charles Oliver Nutter headius

View GitHub Profile
@headius
headius / prism_chicory.rb
Last active January 19, 2024 15:28
Attempting to use Chicory (JVM WASM runtime) to run Prism (C-based Ruby language parser)
%w[runtime wasm wasi].each {|pkg| require "/Users/headius/.m2/repository/com/dylibso/chicory/#{pkg}/0.0.3/#{pkg}-0.0.3.jar"}
module Chicory
%w[
runtime.Module
runtime.HostImports
runtime.wasi.WasiOptions
runtime.wasi.WasiPreview1
wasm.types.Value].each do |cls|
java_import "com.dylibso.chicory.#{cls}"
@headius
headius / gist:3491618
Created August 27, 2012 19:34
JVM + Invokedynamic versus CLR + DLR

Too much for teh twitterz :)

JVM + invokedynamic is in a completely different class than CLR + DLR, for the same reasons that JVM is in a different class than CLR to begin with.

CLR can only do its optimization up-front, before executing code. This is a large part of the reason why C# is designed the way it is: methods are non-virtual by default so they can be statically inlined, types can be specified as value-based so their allocation can be elided, and so on. But even with those language features CLR simply cannot optimize code to the level of a good, warmed-up JVM.

The JVM, on the other hand, optimizes and reoptimizes code while it runs. Regardless of whether methods are virtual/interface-dispatched, whether objects are transient, whether exception-handling is used heavily...the JVM sees through the surface and optimizes code appropriate for how it actually runs. This gives it optimization opportunities that CLR will never have without adding a comparable profiling JIT.

So how does this affect dynamic

@headius
headius / jruby_criu.patch
Last active April 26, 2023 16:37
JRuby CRIU proof-of-concept patch
commit dac864582a44da0017fdc5b85d431c05f40eb675
Author: Charles Oliver Nutter <headius@headius.com>
Date: Sat Apr 22 12:40:27 2023 -0500
criu testing
diff --git a/bin/jruby.sh b/bin/jruby.sh
index 00903f0ba8..fd62212a07 100755
--- a/bin/jruby.sh
+++ b/bin/jruby.sh
@headius
headius / jruby_criu.txt
Last active April 26, 2023 16:02
JRuby using Checkpoint and Restore In Userspace to start up fast
root@e7fc053b9e41:/instantOnDemo/jruby# time jruby -e 'puts "hello!"'
hello!
real 0m5.546s
user 0m9.524s
sys 0m0.796s
root@e7fc053b9e41:/instantOnDemo/jruby# jruby --checkpoint -e 'puts "hello!"'
Warming up JRuby... done! Saving checkpoint.
Killed
root@e7fc053b9e41:/instantOnDemo/jruby# time jruby --restore
@headius
headius / tikka_masala.md
Last active March 26, 2023 21:38
Chicken Tikka Masala

Chicken tikka masala

Time: 50 minutes

Serves: 4-6

Ingredients

diff --git a/core/src/main/java/org/jruby/parser/StaticScope.java b/core/src/main/java/org/jruby/parser/StaticScope.java
index 66c9b71c61..32c644f730 100644
--- a/core/src/main/java/org/jruby/parser/StaticScope.java
+++ b/core/src/main/java/org/jruby/parser/StaticScope.java
@@ -37,6 +37,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.Map;
import java.util.function.BiConsumer;

Code:

def foo
  <<~Q
  Qend

JRuby:

@headius
headius / outline_escape_munging.diff
Created December 20, 2022 04:50
One chunk of code that can be outlined in parser to reduce #advance size by almost 6000 instructions
diff --git a/lib/parser/lexer.rl b/lib/parser/lexer.rl
index e477b06..88efafc 100644
--- a/lib/parser/lexer.rl
+++ b/lib/parser/lexer.rl
@@ -445,6 +445,60 @@ class Parser::Lexer
# Ruby >= 32, regexp, exceptional case
!literal.regexp?
end
+
+ def current_literal_munge_escape(current_literal)
@headius
headius / gist:8428930
Created January 15, 2014 00:58
SecureRandom performance, instance per thread
system ~/projects/jruby-1.7 $ pickjdk 5
New JDK: jdk1.7.0_45.jdk
system ~/projects/jruby-1.7 $ time jruby -J-Djava.security.egd=file:/dev/random securerandom_bench.rb
real 0m4.899s
user 0m26.660s
sys 0m0.361s
system ~/projects/jruby-1.7 $ time jruby -J-Djava.security.egd=/dev/random securerandom_bench.rb
# cat test.rb
class Foo
def bar
puts 'hello, android'
end
end
Foo.new.bar
# dalvikvm -classpath ruboto.jar org.jruby.Main -X-C test.rb
hello, android
# dalvikvm -classpath ruboto.jar org.jruby.Main -X-C -e "require 'java'; puts java.lang.System.properties"