LoginSignup
8
7

More than 5 years have passed since last update.

twigが部分的にPHP拡張になり15%高速化してた

Posted at

気がついたら twig がボトルネックのロジックを部分的にC言語で再実装し、PHP拡張にすることで15%のスピードアップを実現してた→Twig extension

複雑な処理を行なっていた TwigTemplate::getAttribute()twig_template_get_attributes() としてPHP拡張に実装したようで、twig_template_get_attributes() 関数が存在するならこちらを優先して呼ぶ実装になっていた。

とりあえず、今のところはコンパイルして入れればいいみたい:

$ php -v
PHP 5.4.5 (cli) (built: Aug 12 2012 18:49:16) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.2.0, Copyright (c) 2002-2012, by Derick Rethans
git clone https://github.com/fabpot/Twig.git
cd Twig/ext/twig
phpize
./configure
make
make install

php.iniに追記:

extension=twig.so

入った:

$ php -m | grep twig
twig

関数もある:

$ php -a
Interactive shell

php > var_dump(function_exists('twig_template_get_attributes'));
bool(true)
php > exit
8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7