[瓒i椈] 浠g爜椤哄簭涔熶細褰卞搷 LuaJIT 鐨勬墽琛屾晥鐜?/a>
Posted doujiang24
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[瓒i椈] 浠g爜椤哄簭涔熶細褰卞搷 LuaJIT 鐨勬墽琛屾晥鐜?/a>相关的知识,希望对你有一定的参考价值。
鏈€杩戞湁涓€涓湁瓒g殑鍙戠幇锛岃皟鏁翠簡涓€琛?Lua 浠g爜鐨勯『搴忥紝鎵ц鏃堕棿鍗村皯浜嗘帴杩戜竴鍗?馃槄
鐜板満妗堜緥
鎯呭喌涓嬮潰杩欎釜 lua 鑴氭湰 order-1.lua
锛?/p>
local function f2 (...)
return select(\'#\', ...)
end
local function f1 (...)
local l = select(\'#\', ...)
local m = 0
for i = 1, l do
m = m + select(i, ...)
end
local n = f2(...)
return m + n
end
local n = 0
for i = 1, 1000 * 1000 * 100 do
n = n + f1(1, 2, 3, 4, 5)
end
print("n: ", n)
鎵ц鏃堕棿涓?6.3s
锛?/p>
$ time luajit order-1.lua
n: 2000000000
real 0m6.343s
user 0m6.342s
sys 0m0.000s
濡傛灉灏嗗叾涓殑 f1
鍑芥暟瀹炵幇锛岃皟鏁翠竴涓嬮『搴忥細
local function f1 (...)
local n = f2(...)
local l = select(\'#\', ...)
local m = 0
for i = 1, l do
m = m + select(i, ...)
end
return m + n
end
杩欎釜鏀瑰姩鏄皢 n
鐨勮绠楁斁鍒?m
璁$畻鐨勫墠闈€?br>浠庨€昏緫涓婃潵璇达紝m
鍜?n
涓や釜鏄苟娌℃湁椤哄簭渚濊禆锛屽厛绠楀摢涓€涓兘涓€鏍风殑锛屼絾鏄墽琛屾椂闂村嵈灏戜簡灏嗚繎涓€鍗婏細
$ time luajit order-2.lua
n: 2000000000
real 0m3.314s
user 0m3.312s
sys 0m0.002s
鍘熷洜鍒嗘瀽
棣栧厛鑲畾涓嶆槸浠€涔堣寮傞棶棰橈紝璁$畻鏈哄彲鏄汉绫绘渶鐪熷疄鐨勪紮浼翠簡锛屽搱鍝?馃槃
杩欐鏄?Lua 杩欑楂樼骇璇█锛屼篃涓嶆槸 涓婃閭g CPU 鎸囦护绾?/a> 鐨勫奖鍝嶄簡銆?/p>
tracing JIT
杩欐鏄洜涓?LuaJIT 鐨?tracing JIT 鎶€鏈殑褰卞搷銆?/p>
涓嶅儚 Java 閭g method based JIT 鎶€鏈紝鏄寜鐓у嚱鏁版潵鍗虫椂缂栬瘧鐨勩€侺uaJIT 鏄寜鐓?trace 鏉ュ嵆鏃剁紪璇戠殑锛宼race 瀵瑰簲鐨勬槸涓€涓蹭唬鐮佹墽琛岃矾寰勩€?br>LuaJIT 浼氭妸鐑殑浠g爜璺緞鐩存帴鍗虫椂缂栬瘧鐢熸垚鏈哄櫒鐮侊紝涓€涓茬儹鐨勪唬鐮佽矾寰勪篃灏辨槸涓€涓?trace銆傚悓鏃?trace 涔熶笉鏄棤闄愰暱鐨勶紝LuaJIT 鏈変竴濂楁満鍒舵潵鎺у埗 trace 鐨勫紑濮嬬粨鏉燂紙浠ュ悗鎵炬椂闂村啀璇︾粏璁板綍涓€绡囩殑锛夈€?/p>
鍏蜂綋鏉ヨ鏄繖鏍峰瓙鐨勶紝鍥犱负鍦?order-1.lua
閲岋紝TRACE 1
鍦?m
璁$畻鐨勯偅涓?for 寰幆澶勫垯鍋滄浜嗭紝褰?TRACE 2
寮€濮嬬殑鏃跺€欙紝LuaJIT 杩樹笉鏀寔杩欑鎯呭喌涓嬪嵆鏃剁紪璇?锛堣繕澶勪簬 NYI 鐘舵€侊級VARG
杩欎釜瀛楄妭鐮侊紙涔熷氨鏄搴旂殑 ...
锛夈€?/p>
鎵€浠ワ紝瀵艰嚧浜嗚繖閮ㄥ垎浠g爜涓嶈兘琚?JIT锛屽洖褰掑埌浜?interpreter 妯″紡锛屾墍浠ュ鑷翠簡杩欎箞澶х殑鎬ц兘宸紓銆?/p>
濡備笅锛屾垜浠彲浠ュ湪 LuaJIT 杈撶殑鏃ュ織涓湅鍒?NYI: bytecode 71
杩欎釜鍏抽敭淇℃伅銆?/p>
$ luajit -jdump=bitmsr order-1.lua
...
---- TRACE 2 start 1/3 order.lua:13
0016 UGET 2 0 ; f2 (order.lua:13)
0017 VARG 4 0 0 (order.lua:13)
---- TRACE 2 abort order.lua:13 -- NYI: bytecode 71
鎬荤粨
璋冩暣浜?Lua 浠g爜椤哄簭锛屽奖鍝嶄簡 LuaJIT 涓?trace 鐨勭敓鎴愶紝瀵艰嚧浜嗘湁瀛楄妭鐮佹病娉曡 JIT锛岃繖閮ㄥ垎鍥為€€鍒颁簡瑙i噴妯″紡锛屼粠鑰屽鑷翠簡杈冨ぇ鐨勬€ц兘宸紓銆?/p>
鎰熸叏涓€涓?/h3>
JIT 鎶€鏈繕鏄洰濂界帺锛屼笉杩囬渶瑕佸涔犳帉鎻$殑涓滆タ涔熸尯澶氱殑銆?/p>
浠ユ垜鐩墠鐨勭悊瑙o紝tracing JIT 绠楁槸寰堢墰鐨?JIT 鎶€鏈簡锛屾湁鍏舵槑鏄剧殑浼樺娍銆備笉杩囦换浣曚竴椤规妧鏈紝鎬绘槸灏戜笉浜嗛潪甯稿鐨勪汉鍔涙姇鍏ャ€?br>鍗充娇鍍?Lua 杩欑灏忓阀鐨勮瑷€锛屼篃杩樻槸鏈変笉灏戠殑 NYI 娌℃湁琚?JIT 鎶€鏈€?br>鍍?Java 杩欑閲嶅瀷璇█锛孞IT 杩欐柟闈㈢殑鎶€鏈紝鎬曟槸闇€瑕佸緢澶氬ぇ鐗涙墠鍫嗗嚭鏉ョ殑銆?/p>
以上是关于[瓒i椈] 浠g爜椤哄簭涔熶細褰卞搷 LuaJIT 鐨勬墽琛屾晥鐜?/a>的主要内容,如果未能解决你的问题,请参考以下文章