-
Notifications
You must be signed in to change notification settings - Fork 803
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
Computed collections: optimize simple mappings with preludes #17067
Computed collections: optimize simple mappings with preludes #17067
Conversation
* E.g., ```fsharp [let y = f () in for … in … -> …] ``` and ```fsharp [f (); g (); for … in … -> …] ``` are transformed into something like ```fsharp let y = f () in [for … in … -> …] ``` and ```fsharp f (); g (); [for … in … -> …] ``` so that the existing pattern recognition of simple mappings and integral ranges may succeed.
❗ Release notes required
|
…-collections-prelude
Did you manage to VS-breakpoint capabilities and looking into the values, such as seeing the value of |
Thanks for the reminder, I had been meaning to do that. I'll add something to |
This particular part is fine, but it seems like the non-inlined call to Maybe I'll just go ahead and emit loops directly for that instead. Since that will affect more baselines, would you rather I did that in a separate PR? |
That is fine, diff in baselines is expected. |
* Now emit fast map loops directly (instead of calling Array.map and List.map). * Use better ranges for debugging. I don't think these are perfect, but the ranges used for loops are already inconsistent, so I am not exactly sure what perfect would look like. The emission of inlined loops does make stepping through the mapping body work right, though.
…-collections-prelude
Hey Brian, this looks promising - do you have any benchmarks for this also? |
Hmm @T-Gro, it seems like the debugging experience for These reproduce for me if I compile an fsx file using the following command (and in a console app) using the shipped 8.0.204 SDK: dotnet "C:\Program Files\dotnet\sdk\8.0.204\FSharp\fsc.dll" --debug+ --tailcalls- --optimize- .\tests\walkthroughs\DebugStepping\Comparison.fsx For example, stepping through a simple, top-level bare_loop_debug_comparison.mp4There are also some scenarios where breakpoints already cannot be set in computed collections, depending on the combination of comprehension type (list, array, seq), enumerable type (list, array, seq, range), simple body versus sequential expression body, explicit yield versus implicit yield, etc.: unsettable_breakpoints_2.mp4I think the best I can do is try to keep the experience with this update as close as possible to the status quo. I'll let you know when I think it's close enough. |
I reran the benchmarks from #16948, and the results were the same within the margin of error. Those benchmarks were just testing an identity mapping; I'm sure it's possible to come up with a benchmark where you could notice the difference between the inlined loop and the closure invocation in |
Thanks for looking into this and checking it Brian. Keeping the status quo working is a good goal :-). |
Alright, yeah that makes sense. |
FYI, I probably won't have a chance to finish this up till next week. |
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.
LGTM. Thanks for restoring the walkthrough also.
Good job 🚀
Description
Addresses Speed up
for … in xs -> …
in computed collections #16948 (comment).That is, before this, when a
for … in xs -> …
expression was the last expression in the comprehension, but one or morelet
-bindings or sequential expressions preceded it, the simple mapping (Speed upfor … in xs -> …
in computed collections #16948) and integral range (Optimize simple range mappings:[for n in start..finish -> f n]
, &c. #16832) optimizations would not be applied. With this PR, they are.Source code like
and
is now transformed (in an intermediate step) into something like
and
to allow the existing pattern-matching to succeed.
Also updates Speed up
for … in xs -> …
in computed collections #16948 and directly emits fast loops instead of callingArray.map
/List.map
.Checklist
Note to reviewers
When looking at the baselines, it is useful to compare each function's IL with its source, paying specific attention to the order in which things happen: e.g., if two functions
f
andg
are passed in and invoked in that order, ensure that you see theldarg.0
instruction (forf
) before theldarg.1
instruction (forg
), etc. If these happen outside of thefor
-loop in the source, likewise ensure that they do so in the IL: e.g., iff
andg
are called before the loop in the source, and if the loop ends inblt.un.s IL_0022
in the IL, ensure thatf
andg
are loaded and called beforeIL_0022
(or before the call tomap
, depending).(I have looked, and it looks right to me.)