velocity icon indicating copy to clipboard operation
velocity copied to clipboard

Performance

Open shaoshuai0102 opened this issue 9 years ago • 12 comments

  • add compile method to support simple precompiling. More work should be done to achieve further performance improvement.
  • add benchmarks
    1. velocity without precompiling
    2. nunjucks without precompiling
    3. velocity with precompiling
    4. nunjucks with precompiling

shaoshuai0102 avatar May 17 '15 05:05 shaoshuai0102

加了预编译后由于不需要每次都解析AST,执行效率大概是原来的2.5倍,但是跟nunjucks比还是渣渣。后面再优化。

image

shaoshuai0102 avatar May 17 '15 05:05 shaoshuai0102

profile1

node_inspector_-_file____users_shaoshuai0102_projects_velocity_tmp_js

最耗时的竟然是utilx里的类型判断

shaoshuai0102 avatar May 17 '15 15:05 shaoshuai0102

把utilx中的类型判断换成lodash后,性能显著提高,未预编译版本性能超过nunjucks,预编译版本接近达到nunjucks的二分之一

优化前:

3/89bc9582-fc96-11e4-928e-eadd268c6a9c

优化后:

1__shaoshuai0102_shawns-macbook-pro____projects_velocity__zsh__and_updating_iterm

shaoshuai0102 avatar May 17 '15 16:05 shaoshuai0102

可以直接使用了

Sent from my iPhone

On May 18, 2015, at 12:16 AM, Shawn [email protected] wrote:

把utilx中的类型判断换成lodash后,性能显著提高,未预编译版本性能超过nunjucks,预编译版本接近达到nunjucks的二分之一

优化前:

— Reply to this email directly or view it on GitHub.

fengmk2 avatar May 17 '15 16:05 fengmk2

还有优化空间

shaoshuai0102 avatar May 17 '15 16:05 shaoshuai0102

这个PR等等再合并哈,下周有时间再搞搞

shaoshuai0102 avatar May 17 '15 16:05 shaoshuai0102

多余的 commits rebase 合并掉

fengmk2 avatar May 17 '15 17:05 fengmk2

isObject 判断,可以使用最高效的方式: if (obj && typeof obj === 'object' && !Array.isArray(obj))

而且我们如果已经判断了不是数组,后面一步也没必要了

fengmk2 avatar May 17 '15 17:05 fengmk2

lodash里的isObject也是这么做的。你说的几个我再改改看看性能提升

shaoshuai0102 avatar May 18 '15 01:05 shaoshuai0102

ppp

改好了,不再调用lodash,都是现场判断掉了。性能又提高了一点点,到了nunjucks 1/2水平了。

benchmark不是特别精准,有时能到1/2,有时到不了。

shaoshuai0102 avatar May 18 '15 03:05 shaoshuai0102

这个还没合

popomore avatar Dec 21 '15 08:12 popomore

ms 邵帅说他再改改,然后我就忘记关注了

fool2fish avatar Dec 23 '15 09:12 fool2fish