Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Callables should handle null args and kwargs #864
When functions are called, two data structures are created to hold their arguments: a java array for the args and a java hashmap for the kwargs. These are created even when the callable takes no arguments. We can prevent creating these empty data structures by making sure there are sufficient null checks when the callable is invoked.
(This is a copy of this PR)
I'm unable to show that this change results in a performance boost, and I think this is because while not creating some arrays and hashmaps that will just be empty is an improvement, the extensive null checking on invocation cancels out the savings. If that is the case, I'm not sure this PR is a good idea because it could mean that performance worsens a bit for callables that do take arguments but we have to do the null checking anyway. Thoughts @freakboy3742? :-)
The code that's here is good; but I think you've missed a couple of opportunities for optimisation, which possibly explains why you're not seeing an speedup. You've optimized the bytecode creation around invoking the function call, but the logic handling the invocation is just as complex (possibly more so, because there extra branch instructions).
I think if you dig into the invoke methods and to find paths that avoid creating new empty arrays, you might see a speedup.
It appears that the reason why I can't write a benchmarking test to show the performance improvement is because the preparation for making a function invocation (the site of this optimization) is miniscule compared to the cost of making a function call. I reached this conclusion because a) the bytecode of the benchmark test I wrote is smaller (see gist here) and b) there is no noticeable performance difference between invoking functions that don't take arguments and functions that do (see gist here).