toLua Framework是一款开源的Unity+toLua热更新框架,越来越多的游戏项目将其应用于热更新开发,但这样会形成了Lua+Mono双GC系统,而有的开发人员优化时往往只针对Mono层的优化而忽略Lua层的性能问题,或者没有类似于Unity Profiler这样高效直观的优化工具,又或者认为Lua拥有类似于C#的垃圾自动回收机制而不必优化。其实,Lua使用不规范也会造成灾难性的性能问题。
例图:Unity Profiler只能追踪到C#层与Lua层的交互代码块,而无法具体分析Lua层
参考资料:
https://www.jianshu.com/p/19f03570a117
https://blog.uwa4d.com/archives/USparkle_Lua1.html
https://blog.uwa4d.com/archives/2037.html
1. LuaProfiler
简述:有点年代的官方产品,可以统计出包括代码执行次数、平均时长、总时间消耗在内的更多信息,更多详情可以点击官方介绍查看。
官网下载地址:http://luaprofiler.luaforge.net/index.html#download
GitHub地址:https://github.com/luaforge/luaprofiler
其他下载地址:https://www.cnblogs.com/lightsong/p/5576100.html
使用手册:http://luaprofiler.luaforge.net/manual.html
源码解析:https://www.jianshu.com/p/f6606b27e9de
toLua Framework集成:https://www.jianshu.com/p/19f03570a117
2. 云风的LuaProfiler
简述:比较简单 Lua 性能分析工具,注意的是很多函数都是Lua 5.2和Lua 5.3版本之后才有的函数。
GitHub地址:https://github.com/cloudwu/luaprofiler
toLua Framework集成:https://www.jianshu.com/p/19f03570a117
1. 云风的Snapshot
简述:比较简单的一个Lua内存分析工具,通过对比代码段执行前后全局变量的快照进而排查Lua对象是否存在泄露。
博客地址:https://blog.codingnow.com/2012/12/lua_snapshot.html
GitHub地址:https://github.com/cloudwu/lua-snapshot
toLua Framework集成:https://www.jianshu.com/p/19f03570a117
2. Luacheck
简述:网上一个Lua检查工具,还没研究过,功能很多。
使用手册:https://luacheck.readthedocs.io/en/stable/
GitHub地址:https://github.com/mpeterv/luacheck
3. LuaMemorySnapshotDump
简述:从Lua的Registry或者_G开始往下递归查找,找到所有为null userdata的对象(null userdata,在toLua方案中表示是一个C#对象,并且Equals null),并且可以反向列出该对象的引用链,直到Registry或_G为止。这样就可以详细的定位是哪个Lua对象造成了问题。
博客地址:https://www.cnblogs.com/yaukey/p/unity_lua_memory_leak_trace.html#4313499
GitHub地址:https://github.com/yaukeywang/LuaMemorySnapshotDump
简述:大神们写的一款类似于Unity Profiler的Lua调试利器,可以将C#和Lua的整个函数调用过程展示在你面前,并且支持真机调试。
博客地址:https://www.zhihu.com/question/307064711/answer/570257565
使用教程:https://zhuanlan.zhihu.com/p/57051520
下载地址:https://github.com/ElPsyCongree/LuaProfiler-For-Unity或https://gitee.com/Sziye/LuaProfiler-For-Unity#installe_zh
界面展示:
参考资料:
https://blog.uwa4d.com/archives/2037.html
https://blog.uwa4d.com/archives/usparkle_luaperformance.html
https://www.zhihu.com/question/307064711/answer/570257565