Skip to content
Permalink
Browse files

Reduce per-invocation NativeCall overhead

By lifting the most common cases out, avoiding calls and a lock
acquisition, we can make quite some savings on each native call that
we do. On a SQLite/DBIish benchmark, which is extremely native call
heavy, this is worth over 10%.
  • Loading branch information...
jnthn committed Jan 8, 2019
1 parent 225d2f9 commit 6b078a052a7c71c3310dfb927682440d3b65eab4
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/NativeCall.pm6
@@ -288,7 +288,6 @@ our role Native[Routine $r, $libname where Str|Callable|List|IO::Path|Distributi
return_hash_for($r.signature, $r, :$!entry-point));
$!rettype := nqp::decont(map_return_type($r.returns)) unless $!rettype;
$!arity = $r.signature.arity;
($*W && $*W.is_precompilation_mode ?? $!precomp-setup !! $!setup) = $jitted ?? 2 !! 1;

$!any-optionals = self!any-optionals;

@@ -305,6 +304,8 @@ our role Native[Routine $r, $libname where Str|Callable|List|IO::Path|Distributi
Code.HOW.invocation_attr_name(Code),
nqp::null());
}

($*W && $*W.is_precompilation_mode ?? $!precomp-setup !! $!setup) = $jitted ?? 2 !! 1;
}
}

@@ -564,10 +565,11 @@ our role Native[Routine $r, $libname where Str|Callable|List|IO::Path|Distributi

method CALL-ME(|args) {
self.create-optimized-call() unless
$!is-clone # Clones and original would share the invokespec but not the $!do attribute
$!optimized-body # Already have the optimized body
or $!is-clone # Clones and original would share the invokespec but not the $!do attribute
or $!any-optionals # the compiled code doesn't support optional parameters yet
or $*W; # Avoid issues with compiling specialized version during BEGIN time
self!setup();
self!setup() unless $!setup;

my Mu $args := nqp::getattr(nqp::decont(args), Capture, '@!list');
if nqp::elems($args) != $!arity {

0 comments on commit 6b078a0

Please sign in to comment.
You can’t perform that action at this time.