-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
FfiCall.Handlex01(RunTime): 347.8671304347826 us.
FfiCall.Handlex02(RunTime): 384.86376755820663 us.
FfiCall.Handlex04(RunTime): 492.896007885658 us.
FfiCall.Handlex10(RunTime): 846.1214043993232 us.
FfiCall.Handlex20(RunTime): 1193.412291169451 us.
We currently call into C for every handle with
sdk/runtime/vm/compiler/frontend/kernel_to_il.cc
Lines 2750 to 2764 in 755686e
Fragment FlowGraphBuilder::AllocateHandle(LocalVariable* api_local_scope) { | |
Fragment code; | |
if (api_local_scope != nullptr) { | |
// Use the reference the scope we created in the trampoline. | |
code += LoadLocal(api_local_scope); | |
} else { | |
// Or get a reference to the top handle scope. | |
code += GetTopHandleScope(); | |
} | |
Value* api_local_scope_value = Pop(); | |
auto* instr = new (Z) AllocateHandleInstr(api_local_scope_value); | |
Push(instr); | |
code <<= instr; | |
return code; | |
} |
sdk/runtime/vm/runtime_entry.cc
Lines 3559 to 3570 in 755686e
extern "C" LocalHandle* DLRT_AllocateHandle(ApiLocalScope* scope) { | |
CHECK_STACK_ALIGNMENT; | |
TRACE_RUNTIME_CALL("AllocateHandle %p", scope); | |
LocalHandle* return_value = scope->local_handles()->AllocateHandle(); | |
TRACE_RUNTIME_CALL("AllocateHandle returning %p", return_value); | |
return return_value; | |
} | |
DEFINE_RAW_LEAF_RUNTIME_ENTRY( | |
AllocateHandle, | |
1, | |
false /* is_float */, | |
reinterpret_cast<RuntimeFunction>(&DLRT_AllocateHandle)); |
Instead, we can extend the EnterHandleScope with an int how many handles we want, and do some integer arithmetic in IL to compute the addresses of those handles. (Up to the number of handles that fit into one single block.)
sdk/runtime/vm/compiler/frontend/kernel_to_il.cc
Lines 2731 to 2736 in 755686e
Fragment FlowGraphBuilder::EnterHandleScope() { | |
auto* instr = new (Z) | |
EnterHandleScopeInstr(EnterHandleScopeInstr::Kind::kEnterHandleScope); | |
Push(instr); | |
return Fragment(instr); | |
} |