-
Notifications
You must be signed in to change notification settings - Fork 783
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
Inline List.iter/List.iteri for performance #8176
Conversation
@TIHan Could it also be applied to arrays and sequences iteration? |
@auduchinok There is interesting behavior when it comes to the inlining of functions. The compiler can decide to inline a function even when it is not marked AFAIK, a local function's implementation will be optimized first, which in itself could contain functions that could inline themselves. This affects the size of the overall function and may cause the function not to inline when called and have to create an allocation. This is the behavior of an inlined |
This is ready, just need a review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if you revert your recent changes where you manually converted to for loop?
So, the inline List.iter/List.iteri is fine, but I am going to separate out the specific optimizer change in a different PR. |
@forki I just built it and yea, it did not optimize it =/ - means I do not have a good test. However, the test that is there is passing as a result of the change and failing if the change isn't in place. Also, if I do not use partial application, it will be optimized with no allocation, even without the optimizer change. and CheckTypesDeep cenv f g env tys =
tys |> List.iter (CheckTypeDeep cenv f g env true) to this: and CheckTypesDeep cenv f g env tys =
tys |> List.iter (fun ty -> CheckTypeDeep cenv f g env true ty) |
@TIHan want to remove the WIP? |
@@ -100,7 +100,7 @@ namespace Microsoft.FSharp.Collections | |||
loop ([], state) (rev list) | |||
|
|||
[<CompiledName("Iterate")>] | |||
let iter action list = Microsoft.FSharp.Primitives.Basics.List.iter action list | |||
let inline iter action (list:'T list) = for x in list do action x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. A bit surprised that these older, unoptimized functions for lists are still in use.
Ok @TIHan so something is wrong with optimization of partial application? That should be investigated further |
@forki Definitely should be investigated. I'm still going to look at it. |
XOXO |
This inlines
List.iter/List.iteri
for performance reasons. Normally I do not like inlining core functions in FSharp.Core because of the potential to expose internals. But, this does not show any of those downsides.This is in reaction to this PR: #8175
It doesn't solve the main problem that the PR describes though. There is optimization behavior that is still causing a function allocation.