Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance #30

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

shaoshuai0102
Copy link
Contributor

  • 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
Copy link
Contributor Author

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

image

@shaoshuai0102
Copy link
Contributor Author

profile1

node_inspector_-_file____users_shaoshuai0102_projects_velocity_tmp_js

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

@shaoshuai0102
Copy link
Contributor Author

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

优化前:

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

优化后:

1__shaoshuai0102_shawns-macbook-pro____projects_velocity__zsh__and_updating_iterm

@fengmk2
Copy link
Collaborator

fengmk2 commented May 17, 2015

可以直接使用了

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.

@shaoshuai0102
Copy link
Contributor Author

还有优化空间

@shaoshuai0102
Copy link
Contributor Author

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

@fengmk2
Copy link
Collaborator

fengmk2 commented May 17, 2015

多余的 commits rebase 合并掉

// do nothing
} else if (utilx.isString(context)) {
} else if (_.isString(context)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodejs里没有,现在只有iojs里有,等以后新版本应用多了再试。lodash已经优化的不错了

@fengmk2
Copy link
Collaborator

fengmk2 commented May 17, 2015

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

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

@fengmk2 fengmk2 self-assigned this May 17, 2015
@shaoshuai0102
Copy link
Contributor Author

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

@shaoshuai0102
Copy link
Contributor Author

ppp

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

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

@popomore
Copy link

这个还没合

@fool2fish
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants