-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add a word in the manual about performance of keyword arguments #10443
Comments
There is something about keywords in the performance section of the manual. But it is not clear on the points you mention here. See also comments issue #9551. |
@nalimilan At least by my understanding, your description sounds about right. Keyword arguments are implemented internally by creating a Vector{Any} of keyword/argument pairs, sorting them, and passing them as positional arguments to an internal function. As a consequence, type inference for the return type is constrained only by the types of the keyword arguments in the method definition and not by the types the method is called with. There is no reason to use a method with keyword arguments as a wrapper for an internal version because that's how they're implemented anyway. If no keyword arguments are passed to a function that could accept keyword arguments, then the Vector{Any} construction and sorting steps are elided, so there's no overhead, and type inference uses the inferred types of the specified defaults to determine the return type. If you're not careful you can easily create a function that is inferred correctly when no keyword arguments are passed, but is inferred as Any if some or all of the keyword arguments are passed. |
Is this still not documented well? |
Think this can be closed with the new keyword implementation. |
I'm still not clear about what are the performance implications of keyword arguments, and I recently noted on the mailing list that I'm not the only one. So I think we should add something to the manual about it.
If I understand correctly [1], methods are specialized based on the type of keyword arguments, just like for positional ones, but type inference on the result is not good. There's also an overhead on function calls due to matching keyword arguments. Is that right? Does it still improve performance to use a method with keyword arguments as a mere wrapper for an internal version with only positional arguments?
Finally, it could be good to specify which performance issues are expected to be solved at some point, and which ones are by design. When designing an API, one may prefer taking a (reasonable) performance penalty in the short term and benefit from the nicer function signature in the long term.
1: https://groups.google.com/d/msg/julia-users/iFo6RmppCkE/NbVGcNPmB_oJ
The text was updated successfully, but these errors were encountered: