From: "Marcin Mielżyński" Date: 2008-01-13T11:15:25+09:00 Subject: Re: 1.9 significantly slower than 1.8 on Mac Derek Chesterfield pisze: > > $ ruby -v >> ruby 1.8.6 (2007-09-24 patchlevel 111) [universal-darwin9.0] > > $ ruby logreport2.rb >> user system total real >> Simple: 7.960000 0.000000 7.960000 ( 7.965567) > > $ ruby19 -v >> ruby 1.9.0 (2007-12-25 revision 14709) [i686-darwin9.1.0] > > $ ruby19 logreport2.rb >> user system total real >> Simple: 13.750000 0.010000 13.760000 ( 13.754742) > > Ruby 1.9 uses Oniguruma which is an encoding agnostic engine. e.g: /src: (.*?);/ compiles down to: [exact5:src: ] [mem-start:1] [jump:(1)] [anychar] [push:(-6)] [mem-end:1] [exact1:;] [end] seemingly simple match: /src: (.*?);/ =~ "src: 172.25.20.79;" turns out to: 0> "src: 17..." [exact5:src: ] 5> "172.25...." [mem-start:1] 5> "172.25...." [jump:(1)] 5> "172.25...." [push:(-6)] 5> "172.25...." [mem-end:1] 5> "172.25...." [exact1:;] 5> "172.25...." [anychar] 6> "72.25.2..." [push:(-6)] 6> "72.25.2..." [mem-end:1] 6> "72.25.2..." [exact1:;] 6> "72.25.2..." [anychar] 7> "2.25.20..." [push:(-6)] 7> "2.25.20..." [mem-end:1] 7> "2.25.20..." [exact1:;] 7> "2.25.20..." [anychar] 8> ".25.20...." [push:(-6)] 8> ".25.20...." [mem-end:1] 8> ".25.20...." [exact1:;] 8> ".25.20...." [anychar] 9> "25.20.7..." [push:(-6)] 9> "25.20.7..." [mem-end:1] 9> "25.20.7..." [exact1:;] 9> "25.20.7..." [anychar] 10> "5.20.79..." [push:(-6)] 10> "5.20.79..." [mem-end:1] 10> "5.20.79..." [exact1:;] 10> "5.20.79..." [anychar] 11> ".20.79;" [push:(-6)] 11> ".20.79;" [mem-end:1] 11> ".20.79;" [exact1:;] 11> ".20.79;" [anychar] 12> "20.79;" [push:(-6)] 12> "20.79;" [mem-end:1] 12> "20.79;" [exact1:;] 12> "20.79;" [anychar] 13> "0.79;" [push:(-6)] 13> "0.79;" [mem-end:1] 13> "0.79;" [exact1:;] 13> "0.79;" [anychar] 14> ".79;" [push:(-6)] 14> ".79;" [mem-end:1] 14> ".79;" [exact1:;] 14> ".79;" [anychar] 15> "79;" [push:(-6)] 15> "79;" [mem-end:1] 15> "79;" [exact1:;] 15> "79;" [anychar] 16> "9;" [push:(-6)] 16> "9;" [mem-end:1] 16> "9;" [exact1:;] 16> "9;" [anychar] 17> ";" [push:(-6)] 17> ";" [mem-end:1] 17> ";" [exact1:;] 18> "" [end] match at 0 The bottleneck here is the anychar (OP_ANYCHAR in regexec.c) instruction which uses 'enclen' and 'is_mbc_newline' (which are function pointers, so impossible to be inlined). Joni goes a bit further and uses a bunch of singlebyte specialized opcodes when it detects singlebyte encoding being used. lopex