Rails for Ruby 1.9
moriq
[email protected]
1
もくじ
•Ruby 1.8 vs 1.9
•Rails for Ruby 1.9
•Install Ruby 1.9
•Benchmark
2
Release schedule
•Ruby 1.8.6 – 2007/03
•Rails 1.2.3
•Ruby 1.9.1 – 2007/12
–この時点でRailsも動くと嬉しい
3
Ruby 1.8 vs 1.9
4
Quiz #1 String
p "A"[0]
p ?A
5
Quiz #1 String
p "A"[0]
65 "A"
p ?A
65 "A"
6
Quiz #1 String
p "A".ord
65
p 65.chr
"A"
7
Quiz #1 String
•Stringはbytecodeの配列
•Stringは文字の配列
8
Quiz #2 Array
x=[0,1];x[0,1]=nil;p x
y=[0,1].zip([2,3]);p y
9
Quiz #2 Array
x=[0,1];x[0,1]=nil;p x
[1]
[nil,1]
10
Quiz #2 Array
Array#[]=nil
• 要素を削除
• 値としてnilを設定
ENV['…'] = nil
ENV.delete('…')
11
Quiz #2 Array
y=[0,1].zip([2,3]);p y
[[0,2],[1,3]]
#<Enumerable::Enumerator:>
•Streamを効率的に扱う
12
Quiz #3 when
x=1
p case x
when 1: "A"
when 2: "B"
end
13
Quiz #3 when
"A"
syntax error,
unexpected ':', expecting
keyword_then or ',' or ';' or '\n'
when 1: "A"
^
syntax error,
unexpected keyword_when,
expecting $end
when 2: "B"
^
14
Quiz #3 when
•コロン':'は貴重な資源
–Symbol :foo
–Module Foo::Bar
–Hash
{x:1,y:2}
–Keyword arguments
(Ruby2.0?) x:,y: = {x:1,y:2}
15
Quiz #3 when
x=1
p case x
when 1; "A"
when 2; "B"
end
16
Quiz #4 send
class C
def one() 1 end
private :one
end
p C.new.send(:one)
17
Quiz #4 send
1
in `<main>': private method
`one' called for #<C:0xc285a8>
(NoMethodError)
18
Quiz #4 send
class C
def one() 1 end
private :one
end
p C.new.funcall(:one)
p C.new.__send!(:one)
19
Quiz #4 send
public
protected
private
send
Y
N
N
funcall
Y
N
Y
20
Ruby 1.8 vs 1.9
•文法: ほぼ同じ
•メソッド: 非互換あり
21
Rails for Ruby 1.9
22
Rails for Ruby 1.9
•Ruby 1.9対応Railsを作る
–Ruby trunk (v1.9.0)
–Rails 1-2 branch (v1.2.*)
•ActiveSupport
•ActionPack
•ActiveRecord
23
Dependency
• Railsが依存する外部ライブラリ
–DB binding, Web server
–Rake, RubyGems
–cgi.rb
• Railsだけの対応では済まない
24
Unstable…
•Ruby 1.9はまだ不安定
–[BUG]との戦い
•Railsは安定性が最重要
–ゆっくり移行
25
Test First!
•テストも1.9対応は必要
•Rubyの変更に弱い
2007-03-15:
AS: 8F 6E
AP: 1F 0E
AR: 7F 0E
(base_test only)
26
Optimizing
•新仕様を使って効率改善
–Class variable
–*_methods
–BasicObject
27
Resources
Project site:
http://collaboa.moriq.com/
SVN repos:
http://dev.moriq.com/svn/
local/rails/
28
Install Ruby 1.9
29
Install Ruby 1.9
•1.8環境と共存させる
–configure options
–注意: #!, `ruby`
•RubyGemsのしくみ
–$GEM_HOME
–1.9で動作[ruby-dev:30582]
30
configure options
--enable-shared
--prefix=~/c
--program-suffix=-1.8.6
/home/moriq/c/bin/
ruby-1.8.6
31
shebang #!
~/c/bin/gem:
#!/usr/bin/env ruby
~/c/bin/rake:
#!/home/moriq/c/bin/
ruby-1.8.6
32
call ruby
rake/Rakefile:
`ruby -Ilib ./bin/rake
--version`
33
Install Ruby 1.9
•1.8環境と共存させる
–configure options
–注意: #!, `ruby`
•RubyGemsのしくみ
–$GEM_HOME
–1.9で動作[ruby-dev:30582]
34
$GEM_HOME
/usr/lib/ruby/gems/1.8/…
export GEM_HOME=~/c
/home/moriq/c/
cache/
doc/
gems/
specifications/
35
Gemの構造
tar xvf cache/sources-0.0.1.gem
data.tar.gz
-> lib/sources.rb
metadata.gz
-> metadata (YAML)
•Zlib::GzipReader
– 1.9で動作[ruby-dev:30582]
36
Benchmark
37
Benchmark
•benchmark.rb
–注意: GC, IO
•profiler
–set_trace_func
–Ruby trunkでは動かない
38
Rails Bench
•gems vs vendor
–あまり影響しない
•ActiveSupport
–requireすると遅くなる
–なぜ?
39
ActiveRecord Bench
sqlite3-ruby select (n=1000):
• 1.8.6: 2147 req/sec
• 1.9.0: 2320 req/sec
with ActiveRecord:
• 1.8.6: 1100 req/sec
• 1.9.0: 804 req/sec
40
ActionPack Bench
dispatch (n=100):
• 1.8.6: 108 req/sec
• 1.9.0: 126 req/sec
with AR (2 records):
• 1.8.6: 85.2 req/sec
• 1.9.0: 96.2 req/sec
41
Bottleneck?
•ActiveSupportあやしい
•require 'active_record'
の有無を条件に計測
•GCが効いている
42
sqlite3-ruby benchmark
Avg. runtime (msec)
0.7
0.6
0.5
0.4
bm3as-190
bm3as-186
0.3
bm3-190
bm3-186
0.2
10
100
1000
Runs
43
10000
まとめ
•Rails for Ruby 1.9は
そこそこ動作します
•Ruby 1.9を使ってみよう
44
おわり
45
ダウンロード

Rails for Ruby 1.9