Skip to content

Instantly share code, notes, and snippets.

View headius's full-sized avatar

Charles Oliver Nutter headius

View GitHub Profile
@headius
headius / gist:8811028
Created February 4, 2014 19:52
Counting 1 to 100m across various modes.
system ~/projects/jruby $ jruby --disable-gems -Xir.unboxing=true -X+CIR -e "c = 0; while c < 10; c += 1; t = Time.now; i = 0; while i < 100_000_000; i += 1; end; puts Time.now - t; end"
0.775
0.782
0.777
0.772
0.767
0.778
0.757
0.761
0.781
@headius
headius / gist:9149887
Created February 22, 2014 07:01
Sampled profile of the BigMath.PI method in JRuby.
Flat profile of 137.72 secs (9757 total ticks): main
Interpreted + native Method
0.5% 47 + 0 java.math.BigDecimal.createAndStripZerosToMatchScale
0.1% 9 + 0 org.jruby.ast.WhileNode.interpret
0.0% 2 + 0 org.jruby.parser.RubyParser.<clinit>
0.0% 2 + 0 org.jruby.runtime.Helpers.restructureBlockArgs19
0.0% 2 + 0 jnr.x86asm.INST_CODE.<clinit>
0.0% 1 + 1 java.lang.invoke.MethodHandleNatives.resolve
0.0% 2 + 0 org.jruby.RubyString.cat19
$ rvm ruby-2.1 do ruby -e "def foo(a); self; end; 10.times { t = Time.now; i = 0; while i < 10_000_000; foo(a: 1, b: 2, c: 3); i+=1; end; puts Time.now - t }"
6.850559
6.785051
6.857232
6.761483
6.942781
6.735549
6.705151
6.95679
7.296288
@headius
headius / 1.jruby.txt
Last active August 29, 2015 13:58
Confirmation that JRuby is unaffected by Heartbleed
system ~/projects $ git clone git@github.com:emboss/heartbeat.git
Cloning into 'heartbeat'...
remote: Counting objects: 29, done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 29 (delta 9), reused 25 (delta 5)
Receiving objects: 100% (29/29), 5.46 KiB | 0 bytes/s, done.
Resolving deltas: 100% (9/9), done.
Checking connectivity... done
system ~/projects $ cd heartbeat
@headius
headius / gist:18b13017e1a6cdd1d297
Created May 23, 2014 19:28
Selectable process IO on JRuby...normally impossible on JVM
system ~/projects/jruby $ cat process_select.rb
io = open("|cat", "r+")
Thread.new {
loop {
sleep 1
io.write("hello")
}
}
Thread.new {
@headius
headius / gist:ca4c8f5c4f70c794950a
Created June 2, 2014 07:38
Patches to improve Time.parse performance.
diff --git a/core/src/main/java/org/jruby/RubyHash.java b/core/src/main/java/org/jruby/RubyHash.java
index 661d394..9dadce6 100644
--- a/core/src/main/java/org/jruby/RubyHash.java
+++ b/core/src/main/java/org/jruby/RubyHash.java
@@ -1624,7 +1624,13 @@ public class RubyHash extends RubyObject implements Map {
iteratorVisitAll(new Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
- if (block.yieldArray(context, RubyArray.newArray(runtime, key, value), null, null).isTrue()) {
+ IRubyObject ret;
@headius
headius / gist:534f5ec7be7821d21e9a
Created June 2, 2014 07:54
Profile of Time.parse
percent live alloc'ed stack class
rank self accum bytes objs bytes objs trace name
1 2.59% 2.59% 1166752 7676 21810784 143492 476388 org.joni.ByteCodeMachine
2 1.40% 3.99% 628336 11723 628336 11723 300000 char[]
3 1.30% 5.28% 583072 3836 10924240 71870 424776 org.joni.ByteCodeMachine
4 0.69% 5.98% 311504 8469 311504 8469 300000 java.lang.Object[]
5 0.68% 6.66% 307160 7679 5750800 143770 358836 org.jruby.RubyHash$RubyHashEntry
6 0.68% 7.34% 307040 7676 5739680 143492 476389 org.jruby.RubyRegexp$SearchMatchTask
7 0.68% 8.02% 307040 7676 5738440 143461 493249 org.jruby.RubyString
8 0.65% 8.67% 291688 1919 5452544 35872 491901 org.joni.ByteCodeMachine
@headius
headius / gist:252206b478018d71d85b
Last active August 29, 2015 14:02
Built-in atomic variables for JRuby...hopefully we can get this into Ruby 2.2

Currently, in order to have atomic operations in Ruby you must use my "atomic" gem. Ideally, we'd have VM-level support for atomic operations on instance variables, to enable us to build higher-level concurrency abstractions efficiently.

See https://bugs.ruby-lang.org/issues/8259 if you'd like to contribute to this effort.

>> class Foo
>> attr_accessor :bar, atomic: true
>> end
=> nil
&gt;&gt; hello, goodbye = 'hello'.freeze, 'goodbye'.freeze
@headius
headius / gist:fad70bf08a1ebc96dc68
Created July 6, 2014 05:20
Patch to use a pooled Object[] in IR interpreter in JRuby
diff --git a/core/src/main/java/org/jruby/ir/IRScriptBody.java b/core/src/main/java/org/jruby/ir/IRScriptBody.java
index bdbd656..bc59880 100644
--- a/core/src/main/java/org/jruby/ir/IRScriptBody.java
+++ b/core/src/main/java/org/jruby/ir/IRScriptBody.java
@@ -108,9 +108,9 @@ public class IRScriptBody extends IRScope {
context.preMethodScopeOnly(currModule, scope);
context.setCurrentVisibility(Visibility.PRIVATE);
- Interpreter.runBeginEndBlocks(getBeginBlocks(), context, self, null);
+ Interpreter.runBeginEndBlocks(getBeginBlocks(), context, self, null, -1);
@headius
headius / source.rb
Last active August 29, 2015 14:04
FINALLY, real UNIX-style process mgmt on JRuby
system ~/projects/jruby $ cat blah.rb
in_c, in_p = IO.pipe
out_p, out_c = IO.pipe
err_p, err_c = IO.pipe
pid = spawn('cat', :in => in_c, :out => out_c, :err => err_c)
[in_c, out_c, err_c].each(&:close)
in_p.puts("hello, world")
in_p.close
puts out_p.read
Process.waitpid(pid)