Yapc Na 2013 Sregex
Yapc Na 2013 Sregex
com
YichunZhang(agentzh)
2013.06.03
Inefficientwebservers,requestbodies andresponsebodiesareprocessedindatachunks.
Weusuallyuseafixedsizebuffereven weareprocessingamuchlargerdatastream.
Backtrackingregexenginessuck.
Thompson'sConstructionAlgorithm comestorescue!
Italsosupportssubmatchcaptures!
Icreatedthesregexlibrarybasedon RussCox'sre1library.
sregexiswritteninpureC.
sregexincludestwoengines: ThompsonVM&PikeVM.
^ $ \ A \ z \ b \ B . \ c [ 0 9 a z ] [ ^ 0 9 a z ] \ d \ D \ s \ S \ h \ H \ v \ V \ w \ W \ c K \ N a b a | b ( a ) ( ? : a ) a ? a * a + a ? ? a * ? a + ? a { n } a { n , m } a { n , } a { n } ? a { n , m } ? a { n , } ? \ t \ n \ r \ f . . .
TheregexJITcompilerusesDynASM whichpowersLuaJIT'sinterpreter.
Stillalotofimportantoptimizationstodo.
MyNginxCmodulengx_replace_filter isthefirstuserofsregex.
# s k i p C / C + + s t r i n g l i t e r a l s : r e p l a c e _ f i l t e r " ' ( ? : \ \ [ ^ \ n ] | [ ^ ' \ n ] ) * ' " $ & g r e p l a c e _ f i l t e r ' " ( ? : \ \ [ ^ \ n ] | [ ^ " \ n ] ) * " ' $ & g
r e p l a c e _ f i l t e r _ m a x _ b u f f e r e d _ s i z e 8 k
Thankyou!