Closed zhongwuzw closed 5 years ago
为你的钻研精神点赞,Sonic的目的在于优化单次页面加载速度,首先强调一点这里这个文本替换方法并不会加快或者拖慢页面加载速度,拆分数据目的是在二次加载的时候用来刷新局部数据的,并且拆分模版和动态数据是在子线程进行的异步操作,不会影响主线程,可以肯定的是搜索替换文本方法改为明确range替换是一个更好的方法,我会在之后验证代码执行的结果来确定是否合入PR。
@sonic-ios-dev 谢谢,是的,不会对主线程有大的影响,优化只是减少了split时的CPU占用时间,即从整体上看SonicSessionQueue
的Thread
将会消耗更少的CPU时间片。
@vasdeveloper 咦?这个是最后验证有什么问题么?
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 demomain.html
1000 times, results are below:Used
main.html
:Used
main.html
but has 10 data tag:Used
main.html
but has 20 data tag:Used
main.html
but has 20 data tag, and double file size: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.