-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
specialize loops inside functions #5654
Comments
The |
You're right. Thanks for catching that! |
Superseded by #7311. |
@quinnj I'm not sure how staged functions solve this. Can you elaborate? |
Yeah, this is not the same issue. |
Sorry. I thought that
was exactly what staged functions were getting us. |
The work item here is to identify poorly-typed loops, and carve them out into separate functions that can be specialized at run time. It's an extra compiler optimization pass. |
@quinnj, a staged function will receive that |
While that is true, it can actually throw an error in that case, in which case it will be called again at runtime with the correct types. That's part of the magic :). |
Not sure I understand. What if I explicitly feed it an Now, if you wrote it as
and passed it |
I think the issue is a case where the runtime type information is there but the compile time one isn't so the loop won't be optimized. If there's never good type information then we can't do anything anyway. |
EDIT: Updated the measurement according to @Keno's remark. The issue still stands. |
The issue is for |
While trying to optimize performance of operations on DataFrames, I've found that a recurring pattern underlies a lot of the performance bottlenecks people encounter: functions that take in DataFrames as input don't have enough type information to specialize their implementations for the specific types of the columns stored in a DataFrame. This means that a two-part function that (a) selects a subset of columns to compute on and then (b) performs an intensive computation on those columns can't take advantage of the type information available at the end of part A to improve the performance of part B.
It's possible to articulate this pattern without any reference to DataFrames: you get the exact same effect if you try pulling whole columns out of a
Vector{Any}
and then computing on them. The only workaround I've found is to use an inner function defined inside of the two-part function. This inner function helps to defer type specialization until a time at which it can be carried out effectively.The three examples below highlight this problem:
If you run these functions with the following data, you get very substantial performance differences between the initial naive implementation and the other two:
On my machine, I get relative timings of the following orders of magnitude:
It would be a huge gain to future users of DataFrames if there were a way to make the compiler recognize that a little bit of second-stage type inference could give major performance gains.
The text was updated successfully, but these errors were encountered: