Skip to content
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

Performance tweaks in core/timer.lua #337

Merged
merged 1 commit into from
Dec 10, 2014

Conversation

alexandergall
Copy link
Contributor

The definition of call_timers() in core/timer.lua is moved out of
run_to_time() to avoid generation of the non-compileable bytecode
UCLO (bytecode 51 in the current version of LuaJIT).

Wrapping the call to ffi.C.get_time_ns() in run() with tonumber()
avoids the allocation of a cdata object that is difficult for the sink
optimizer to remove. Here is the IR of a typical trace without tonumber():

0036 > p32 UREFC timer.lua:22 #0
0037 > udt ULOAD 0036
0038 > p32 EQ 0037 [0x4123cfa0]
0039 r15 u64 CALLXS 0x408c78
0040 rax > cdt CNEWI +12 0039
0041 > fun EQ 0035 timer.lua:37

The allocation of the uint64_t cdata object (CNEWI +12) at 0040 is not sunk. With tonumber():

0050 > p32 UREFC timer.lua:22 #0
0051 > udt ULOAD 0050
0052 > p32 EQ 0051 [0x40465fa0]
0053 rax u64 CALLXS 0x408c78
0054 {sink} cdt CNEWI +12 0053
0055 > fun EQ 0049 tonumber
0056 xmm7 num CONV 0053 num.u64
0057 > fun EQ 0035 timer.lua:37

The allocation at 0054 is trivially sunk due to tonumber() acting directly on the return value of the call to get_time_ns().

The definition of call_timers() in core/timer.lua is moved out of
run_to_time() to avoid generation of the non-compileable bytecode
UCLO (bytecode 51 in the current version of LuaJIT).

Wrapping the call to ffi.C.get_time_ns() in run() with tonumber()
avoids the allocation of a cdata object that is difficult for the sink
optimizer to remove.
lukego added a commit that referenced this pull request Dec 10, 2014
Performance tweaks in core/timer.lua
@lukego lukego merged commit 00342a2 into snabbco:master Dec 10, 2014
@lukego
Copy link
Member

lukego commented Dec 10, 2014

Great analysis!!

@alexandergall alexandergall deleted the perf-tweaks-2 branch March 27, 2015 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants