-
-
Notifications
You must be signed in to change notification settings - Fork 200
Tweaks to Trivia::findNodeWhereRangeFitsIn #3169
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
Conversation
- Use Array.tryPick rather than Array.choose |> Array.tryHead - Use Option.orElseWith rather than 'Some betterChild -> Some betterChild'
match betterChildNode with | ||
| Some betterChild -> Some betterChild | ||
| None -> Some root | ||
betterChildNode |> Option.orElseWith (fun () -> Some root) |
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.
Do you think that would perform better? Or this is more of a "I would have written it that way" thing?
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.
The Some betterChild -> Some betterChild
appears to be allocatiing lots of extra instances of Option
, which orElseWith
avoids.
Maybe just doing Some _ -> betterChildNode
would work as well
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.
appears to be allocatiing
Why are you getting that from? The before and after seem rather close?
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.
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.
Alright, thanks for sharing!
@@ -158,12 +158,9 @@ let rec findNodeWhereRangeFitsIn (root: Node) (range: range) : Node option = | |||
// The more specific the node fits the selection, the better | |||
let betterChildNode = | |||
root.Children | |||
|> Array.choose (fun childNode -> findNodeWhereRangeFitsIn childNode range) | |||
|> Array.tryHead | |||
|> Array.tryPick (fun childNode -> findNodeWhereRangeFitsIn childNode range) |
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.
This is the real improvement, is it not?
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.
Thank you!
Would you like a new release for this? |
I don't think there's a need for a release just for this |
refs #3164 (comment)
Rather trivial in the grand scheme of things, but results of the Benchmarks project:
Before:
After:
My laptop is a bit variable with the runtime, but there' no real time change, just a small memory change (155.61MB to 155.24MB with the tryPick change, and to 155.17MB from orElseWith