一次关于Cache的性能分析
Lua5.4-alpha-rc2 已经发布了好一段时间了, 一直没时间去跑跑看性能如何。最近刚好有空,就跑来看看。结果第一段测试代码就把我惊住了。
--a.lua
collectgarbage("stop")
local function foo()
local a = 3
for i = 1, 64 * 1024 * 1024 do
a = i
end
print(a)
end
foo()
在 Lua5.3.4 和 Lua5.4-alpha-rc2 上,这段代码运行时间分为0.55,0.42s。
通过`./luac -p -l ./lua ` 可以得知,上段这代码性能热点一定是OP_MOVE,和OP_FORLOOP。因此一定是这两个opco……