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

Optimize speed of spliting template and data from html data #261

Closed

Conversation

zhongwuzw
Copy link
Contributor

We use - replaceOccurrencesOfString:withString:options:range: to replace tag. But it's not efficient and much time cost. It needs to scan whole file to replace.

I run a performance test to compare the new(my PR) and old(framework currently implementation), split the framework demo main.html 1000 times, results are below:

Used main.html:
image

Used main.html but has 10 data tag:
image

Used main.html but has 20 data tag:
image

Used main.html but has 20 data tag, and double file size:
image

Conclusion:
Along with increasing of data tag or file size, the old method's cost is increasing much higher. For the last test, new split method is at least 6ms faster than old way.

@tencent-adm
Copy link

tencent-adm commented Sep 12, 2018

CLA assistant check
All committers have signed the CLA.

@sonic-ios-dev
Copy link
Contributor

为你的钻研精神点赞,Sonic的目的在于优化单次页面加载速度,首先强调一点这里这个文本替换方法并不会加快或者拖慢页面加载速度,拆分数据目的是在二次加载的时候用来刷新局部数据的,并且拆分模版和动态数据是在子线程进行的异步操作,不会影响主线程,可以肯定的是搜索替换文本方法改为明确range替换是一个更好的方法,我会在之后验证代码执行的结果来确定是否合入PR。

@zhongwuzw
Copy link
Contributor Author

@sonic-ios-dev 谢谢,是的,不会对主线程有大的影响,优化只是减少了split时的CPU占用时间,即从整体上看SonicSessionQueueThread将会消耗更少的CPU时间片。

@zhongwuzw
Copy link
Contributor Author

@vasdeveloper 咦?这个是最后验证有什么问题么?

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

Successfully merging this pull request may close these issues.

None yet

4 participants