ã¦ã½ã¿ãããªæ¬å½ã®è©±ãRuby ã§ãã¡ãã³ã³ã¨ãã¥ã¬ã¼ã¿ãæ¸ãã¦ã¿ã¾ããã
æ°ã«ãªãé度ã§ãããèªåã®ç°å¢ã§ã¯ 20 fps ã¡ãã£ã¨åºã¾ãããã¡ãã³ã³ã¯ 60 fps ãªã®ã§ãå®éã® 1/3 ã§ããRuby3x3 ï¼Ruby 3 㯠Ruby 2 ã® 3 åéãï¼ã¨ãã matz ã®å®£è¨ãå®ç¾ããã°ãå®éãéæããããã¨ã«ãªãã¾ããï¼
試ãã¦ã¿ãã人ã¯ãããªãµãã«å®è¡ãã¦ãã ããã
$ gem install ffi $ git clone http://github.com/mame/optcarrot.git $ cd optcarrot $ bin/optcarrot examples/Lan_Master.nes
SDL2 ã SFML ãé©åã«ã¤ã³ã¹ãã¼ã«ããã¦ããå¿ è¦ãããã¾ããDebian/Ubuntu ãªã apt-get install libsdl2-dev ã§ã
Ruby å¦çç³»ãã³ããã¼ã¯ã¨ãã¦
optcarrot 㯠--benchmark ãªãã·ã§ã³ãä»ãããã¨ã§ããã³ããã¼ã¯ã¢ã¼ãã«ãªãã¾ããGUI ç¡ã㧠180 ãã¬ã¼ã ãå®è¡ããæå¾ã® 10 ãã¬ã¼ã ã®å®è¡æéãã fps ãç®åºãã¦çµäºãã¾ãã
$ ruby bin/optcarrot --benchmark examples/Lan_Master.nes fps: 34.25774482727466 checksum: 59662
ããã㪠Ruby å¦ç系㧠optcarrot --benchmark ãèµ°ããã¦ã¿ãçµæããã¡ãã
MRI 㯠1.8 â 1.9 â 2.0 â 2.3 ã§ç¢ºãã«éã¾ã£ã¦ããã®ããããã¾ãããªãªã¼ã¹æã« "performance improvement" ãªã©ã¨æ¸ããã¦ãããã¤ããªããªãå®æãããã¨ã¯ãªãã§ãããã¦ã½ãããªãã£ããã§ãããMRI é«éå家ã®çããã«æ¬ç¤¼ã
JRuby ã Rubinius ã¯äºæ³å¤ã«é ãã§ãããTopaz ã¯ã本家の 5 倍速?ãã»ã©ã§ã¯ãªãã§ãããå¥éãã¦ã¾ãã*1ï¼è¿½è¨ï¼jruby 㯠-Xcompile.invokedynamic=true 使ãã°ã¹ã¿ã¼ãã¢ããé ããªã代ããã«å¦çé度ãéããªããã¨ã®ãã¨ã§ã試ããã MRI ã«å¹æµãã¾ãããã¡ãªã¿ã« jruby 9k ã®ã¹ãããã·ã§ããçã§ã¯ MRI ã® 2 åãããåºãããã§ããï¼
IBM ã® OMR preview 㯠ruby 2.2 ãã¼ã¹ã§ããã2.2 ããé ããã§ããããJIT ã®é«éåããããããã¡ã¤ã«ã¨ã³ã³ãã¤ã«ã®ãªã¼ãã¼ãããã®æ¹ã大ããããã§ããRuby ã®å ´åãããã«ããã¯ã¯è©ä¾¡å¨ä»¥å¤ã«ãã£ã¦ãJIT ã§é«éåããä½å°ãç¸å¯¾çã«å°ãªãã®ããããã¾ããã
å人çã«æ³¨ç®ãã¦ã»ããã®ã¯ãmruby ã§ãåãã¦ããã¨ããã§ã *2 ãOptcarrot ã¯ãã³ããã¼ã¯ããã°ã©ã ãæèãã¦æ¸ããã®ã§ãRuby ã®åºæ¬çãªæ©è½ï¼ã¨èªåãæããã®ï¼ãã使ã£ã¦ããããå¤é¨ã©ã¤ãã©ãªãä¸å使ç¨ããªã *3 ã®ã§ã移æ¤ãæ¯è¼ç容æã§ãããªã㨠miniruby ã§ãåãã¨ãããRuby å¦çç³»éçºè ã«åªããä»æ§ã
æ³å®è³ªå
ãªããããªãã®ãä½ã£ãã®ï¼
Ruby3x3 ãç ½ããããOSS ã®éçºãé²ããã«ã¯ãéçºè ã¨ãã馬ãèµ°ãããããã®ãã«ãããããå¿ è¦ãã¨ããã®ã¯ matz ããã³ãã³è¨ã£ã¦ãããã¨ã§ããããã§ããã®ãã«ããããã® 1 ã¤ã¨ãªãã°ãããªã¨æã£ã¦ä½ãã¾ãããoptcarrot 㯠optimization carrotï¼æé©åãã³ã¸ã³ï¼ã®ç¥ã§ããRuby3x3 ãéæãããã°ãéçºè ã¯ãã¡ãã³ã³ã²ã¼ã ã§éã¹ãã¨ãããè¤ç¾ãå¾ããã¾ãã
ããããå人çã«ãé ãé ãã¨è¨ããã Ruby ã®éçã«ææ¦ãã¦ã¿ããã£ãã¨ããã®ãããã¾ãããã¡ãã³ã³ã¨ãã¥ã¬ã¼ã¿ã¯ 256 x 240 ã®ç»é¢ã 60 fps ã§ãã¯ã»ã«åä½ã§æç»ããå¿ è¦ãããã¾ããããã Ruby ã£ã¦ãé åã 256 x 240 x 60 åæ´æ°ããã ã㧠0.2 ç§ã¨ãè¦ããããã§ããã確ãã«é ããæ®ãã® 0.8 ç§ã§ CPU ã·ãã¥ã¬ã¼ã·ã§ã³ã¨ãé³æ³¢åæã¨ãããªãããªããªããç¡çã²ã¼ã§ãããã®ç¡çã²ã¼ã«ã©ãã¾ã§å¿ããããããæåã«ãã¤ã¼ãã«æ¸ããã¨ã㯠3 fps ã¨ãã ã£ããã§ãRuby3x3 ã®ã¹ãã¼ãªã¼ã«åãããã« 20 fps ã¾ã§é«éåãã¾ããã7 åãããã®é«éå㯠Ruby ã¬ãã«ã®å·¥å¤«æ¬¡ç¬¬ã§ã©ãã«ã§ããªãã¨ãããã¨ã§ããã
ãã¡ããã¡ãè¨ã£ã¦ããã© 60 fps ã§ãªããã§ããï¼
--opt ãä»ããã°åºãããï¼
$ optcarrot --opt Lan_Master.nes
Optcarrot ã¯ãã³ããã¼ã¯ããã°ã©ã ãªã®ã§ããªãã¹ãæ®éã§ç¶ºéºãªã³ã¼ããæ¸ããã¨ã«ãããã§ããã--opt ãä»ããã¨ç¶ºéºããç ç²ã«ãã¦é«éåãã¾ããå ·ä½çã«ã¯ãã¾ãèªåèªèº«ã®ã½ã¼ã¹ã³ã¼ããèªã¿è¾¼ãã§ãã¡ã½ããã¤ã³ã©ã¤ã³å±éããããç°¡åãªé¨åè¨ç®ããããfastpath ããããããããã¦ãã³ã¼ãã¯ãã¼ã³ã ããã®é«éã ãã©ææªãªã³ã¼ããå é¨çã«çæãã¾ãããã®å¦ç㯠Ruby ã®å¾æã¨ããæååå¦çãªãã§ãæ£è¦è¡¨ç¾ãé§ä½¿ãã¦é©å½ã«ãã£ã¦ã¾ããã§ãçæãããããã°ã©ã æååã eval ãããã¨ã§ããã«ããã¯ã®å¦çãç½®ãæãã¾ããããã§èªåã®ãã¼ããã½ã³ã³ã§ã¯ 60 fps ãéæãã¾ããããã§ããã
ã¾ãããããªãã¨ã¯æ®éã® Ruby ããã°ã©ã ã§ã¯ããã¹ãã§ãªãããããããã£ã¦ãRuby 㧠60 fps éæããï¼ãã¨ä¸»å¼µããã®ã¯ã¡ãã£ã¨ä½ãéããããªæ°ãããã®ã§ããã¾ãæ©è½ã§ãã60 fps åºãã¨ãã¯ããããã£ããã©ããååãã«è¨ãã°ãMRI ãä»å¾ä½ãæé©åãã¦ããã¹ãããèããæææä¾ãããã«ã¯ãªããã¨ã*4
--opt ãå«ãããã³ããã¼ã¯ã¯ãã¡ãã
MRI 以å¤éããªããªãã§ããããã®ã¢ã¼ãã§ã¯å·¨å¤§ãª case æãå é¨çæãããã§ãããcase æãã¸ã£ã³ããã¼ãã«çã«æé©åããã®ã£ã¦ MRI ã ãã½ãã®ã§ããã*5
ã©ããã£ã¦é«éåããã®ï¼
5 æã®æ±äº¬ RubyKaigi 11 ã§çºè¡¨äºå®ã§ãããããæå¾ ã
ä»ããç¥ããã人ã¯ã³ã¼ãèªãã°ããã¨æãã¾ãã
ä½è«
æé©åã£ã¦ããã®ã¯ããããã¾ã§éããªãã°ãããã§ãããéããªããªãã¨ã§ããªããã¨ãããããªãall or nothing ãªç®æ¨ããã£ã¦ããã°ä½ã¨ããªããã®ã ãªãã¨æãã¾ããããã®ãããã§ãã¾ã 3 fps ãã 60 fps ã¾ã§ã® 20 åã®é«éåã§ãé å¼µããããã¨ãã³ã¼ãã®ç¶ºéºãã¨é«éæ§ã®å¦¥åç¹ã決ããããæãããå°ãã§ãããããéãããããã¨ããç ©æ©ã¯ã漫ç¶ã¨ã³ã¼ããæ±ãã°ãã *6 ã§ãæçµçãªå¹æãä¹ããã¨ãããã¨ã«ãªããã¡ã
*1:Topaz ã¯æå 1 fps ã¨ãã ã£ãã®ã§ããããªãã¡ã¯ã¿ãªã³ã°ããã 30 åã«ãªãã¾ãããCPU ã®ãã£ã¹ãããã case æããé ååç §ã«ç½®ãæããã®ãè¯ãã£ãã¿ãããJRuby ã Rubinius ãããã¶ãåæ§ã«ã¡ãã£ã¨ãããã¨ã§éããªããã ããã¨æãã¾ãã
*2:æ´æ°é¤ç®ãæ´æ°ã«ãªãããã«ããããããå½ã¦ã¦ã¾ãã
*3:GUI ã表示ããå ´åã¯ãruby-ffi çµç±ã§ SDL2 ã使ç¨ãã¾ãã
*4:Ruby ã®ããã«ããã¯ã¯æã¨å¤ãããã¡ã½ããå¼ã³åºãã®ã¾ã¾ãªãã ãã¼ã¨ããã¤ã³ã¹ã¿ã³ã¹å¤æ°ã®ã¢ã¯ã»ã¹ã¯é ããªãã¨ãã
*5:Topaz ã¯çæã³ã¼ããè¤éãããããããã³ã³ãã¤ã«ã§ã¨ã©ã¼ã«ãªãã®ã§åãã¾ããã§ããããã ãå¤å Topaz ã case æãæé©åããã¦ãªãã®ã§ã仮㫠--opt ãåãã¦ãä»ãã MRI ãè¶ ãããã¨ã¯ãªãã¨æãã¾ãã
*6:æååãªãã©ã«ã«çã£ç«¯ãã .freeze ã¤ããã¨ããã