Skip to content

Keyword arguments cause slow function calls? #8843

@jeffreyrogers

Description

@jeffreyrogers

This may just be naiveté on my part with regards to writing Julia functions, but I'm seeing a performance hit when adding keyword arguments to function calls.

Basically, I was looking at the implementation of QuickSort and wanted to see if by adding a user-defined cutoff for insertion sort (rather than the built-in constant of 20) I could improve performance. What I found was that simply adding the keyword arguments to function definitions reduced performance substantially (even when the keywords aren't used in the calls). I ran the following both times (results further down):

v = rand(1_000_000)
@time sort(v)
@time sort(v)

I'm calling sort() twice because the second time is always faster (presumably because of the VM generating code the first time around?) Before my change the first call took about 0.23 seconds and the second around 0.10. After the change the first call took about 0.30 seconds and the second 0.16.

Any ideas what is causing this to happen? I think if I reference this issue in a commit you'll be able to see my code. Otherwise, I'll just copy-and-paste the diff.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions