I had an interesting realization tonight: I'm terrified of hash tables. Specifically, my work on JRuby (and even more directly, my work optimizing JRuby) has made me terrified to ever consider using a hash table in the hot path of any program or piece of code if there's any possibility of eliminating it. And what I've learned over the years is that the vast majority of execution-related (as opposed to data-related, purely dynamic-sourced lookup tables) hash tables are totally unnecessary. Some background might be interesting here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
gem 'actionpack', '3.2.3' | |
gem 'activerecord', '3.2.3' | |
gem 'activesupport', '3.2.3' | |
gem 'railties', '3.2.3' | |
gem 'tzinfo' | |
gem 'sqlite3' | |
gem 'thin' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] pry(main)> user = User.new | |
=> #<User @id=nil @email=nil @encrypted_password=nil> | |
[2] pry(main)> User.all | |
=> [#<User @id=1 @email="[email protected]" @encrypted_password="$2a$05$7N1xabSr/SPFJuCKpm62nurvRgsF59GfKu3ZPnK9H9nlnkfytAC62">, #<User @id=2 @email="[email protected]" @encrypted_password="$2a$05$TkRn2veaV/uBEQp0912Vweb2Kf1dnX2DpyM5fk.8SgW7C/ufpwlK6">] | |
[3] pry(main)> user.email = '[email protected]' | |
=> "[email protected]" | |
[4] pry(main)> user.password = 'secretpass' | |
=> "secretpass" | |
[5] pry(main)> user.save | |
=> true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
gem 'minitest' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/setup' | |
Bundler.require :default | |
require 'securerandom' | |
require 'active_support/notifications' | |
require 'active_support/concern' | |
module Events | |
include ActiveSupport::Concern |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.out { | |
color: red; | |
font-family: 'Inconsolata', sans-serif; | |
} |
$ jruby -v
jruby 1.7.0 (1.9.3p203) 2012-10-22 ff1ebbe on Java HotSpot(TM) 64-Bit Server VM 1.6.0_33-b03-424-10M3720 [darwin-x86_64]
$ time jruby -e 'require "rubygems"; require "active_support"'
real 0m1.426s
user 0m2.681s
sys 0m0.180s
$ export JAVA_OPTS='-d32' # switch to 32-bit client mode
$ jruby -v
create a new dir
$ mkdir /tmp/ruby
$ cd /tmp/ruby
create extconf.rb
first, make the Makefile
$ ruby extconf.rb
creating Makefile
next, build the extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> require 'fiddle' | |
=> true | |
>> func = Fiddle::Function.new(DL::Handle::DEFAULT['rb_eval_string'], [DL::TYPE_VOIDP], DL::TYPE_VOIDP) | |
=> #<Fiddle::Function:0x000001010404c8> | |
>> func.call("1 + 1") | |
=> #<DL::CPtr:0x00000101821930 ptr=0x00000000000005 size=0 free=0x00000000000000> | |
>> func.call("1 + 1").to_value | |
=> 2 | |
>> func.call("puts 'hello'").to_value | |
hello |