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

当模板文件比较大时,模板解析速度惨不忍睹 #539

Closed
xqin opened this issue May 11, 2018 · 5 comments
Closed

当模板文件比较大时,模板解析速度惨不忍睹 #539

xqin opened this issue May 11, 2018 · 5 comments

Comments

@xqin
Copy link

xqin commented May 11, 2018

重现POC:

git clone https://github.com/xqin/wtfat.git
cd wtfat
npm install
npm test

问题描述:

当模板文件越大,速度越慢, art-template 的解析速度惨不忍睹.

而同样的模板, 用 underscore, 只需要几毫秒就完成了.

$ npm test

> [email protected] test /Users/xqin/Desktop/Work/at
> node test.js

underscore  6 length 394604
art-template  41526 length 394604
und done
art done

主要问题出在 L93
https://github.com/aui/art-template/blob/master/lib/compile/tpl-tokenizer.js#L93

L38 的正则最后面可以匹配单个字符, L93在不区分任何情况的提前下,直接对value进行split('\n').length 导致, 速度变慢.

@hstarorg
Copy link

关注ing~

@hstarorg
Copy link

https://github.com/aui/art-template/blob/master/lib/compile/tpl-tokenizer.js#L93 此处有无效的split,是否可以考虑增加如下判定:

if (value.length > 1) {
    line += value.split(/\n/).length - 1;
}

@xqin xqin changed the title 当模板中有内联css时,模板解析速度惨不忍睹 当模板文件比较大时,模板解析速度惨不忍睹 May 13, 2018
@aui
Copy link
Owner

aui commented May 14, 2018

我关注下

@kangling098
Copy link

同样的问题,模板文件较大时,编译时间惨不忍睹,1200行html代码居然要渲染将近700ms.......
image

@aui
Copy link
Owner

aui commented Aug 21, 2018

已经修复

@aui aui closed this as completed Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants