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 the performance of SHRINK which use auto wrap. #5914
Conversation
这是为了少调measureText做的优化么 |
是,增加的 Cache 是为了少调用 measureText,Shrink 那里的修改是为了减少匹配计算的次数, issue里有测试说明。 |
if (lambda()) { | ||
right = mid - 1; | ||
} else { | ||
left = mid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么不是 mid + 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么不是 mid + 1
因为 mid 有可能是最终符合要求的size,所以要保留下来。
另外我还有一个疑问是,LRU 缓存和二分查找似乎有点冲突的……
|
这里LRU缓存对于SHRINK的频繁查询来说确实会因为太多的无效字符查询导致缓存空间被占用,但是修改LRU缓存为双向链表的方式,降低查询跟记录时的性能消耗。缓存应该不会带来太多负面影响,对于非SHRINK模式的文本也会有一定改善。 至于SHRINK这种频繁操作跟LRU的冲突,如果通过缓存反向去定位SHRINK的size可能不是很合适了,文本内容可能从多变少,也可能是从少变多,不会比二分快什么。想解决这个问题,LRU可以分成hot跟非hot两个缓存来避免,只有达到一定查询次数之后才从非hot转移到hot部分,查询的时候优先从hot查询,再找非hot区域,不过非hot区域的管理是个问题,会带来一些消耗,这种方式能否接受? |
这确实是一个办法。不过有点复杂了,毕竟不是 C++ 引擎,还是算了吧 |
Re: https://github.com/cocos-creator/2d-tasks/issues/1405
Changes:
优化使用自动换行时的SHRINK性能。