Skip to content
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

MakeCalledArgs allocates a struct tuple #9223

Merged
merged 2 commits into from
May 27, 2020

Conversation

cartermp
Copy link
Contributor

In a trace from here: https://developercommunity.visualstudio.com/content/problem/1035124/trace-of-editing-experience-with-in-memory-cross-p-1.html

I found what looked like needless allocations of a tuple of two integers:

image

This seemed like a needless tupling of two ints, though the values are contained within a larger record that's going on the heap anyways. But in my own testing struct tuples, when it's just things like two ints, is almost always faster for the CPU anyways

@cartermp cartermp requested review from TIHan and dsyme May 18, 2020 00:17
@cartermp
Copy link
Contributor Author

oopsie doopsie daisy, this won't won't do

@forki
Copy link
Contributor

forki commented May 18, 2020

Can't we just use X and Y separately? Then you also don't need to snd on it.

@@ -564,3 +564,4 @@ type MaybeLazy<'T> =
| Strict x -> x
| Lazy x -> x.Force()

let inline vsnd ((_, y): struct('T * 'T)) = y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the ('T*'T) here and not ('a*'b) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this should be ('a * 'b) or ('T * 'U).

@forki
Copy link
Contributor

forki commented May 18, 2020

mhm just looked at it a bit deeper. Position is used in a SortBy and therefore we would probably have to tuple again anway

@cartermp
Copy link
Contributor Author

Yep, this is probably the most minimal/straightforward change if we're interested in knocking down the (small) amount of needless allocations

Copy link
Contributor

@TIHan TIHan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, just minor comment.

@@ -821,7 +821,7 @@ let OutputPhasedErrorR (os: StringBuilder) (err: PhasedDiagnostic) (canSuggestNa
let nameOrOneBasedIndexMessage =
x.calledArg.NameOpt
|> Option.map (fun n -> FSComp.SR.csOverloadCandidateNamedArgumentTypeMismatch n.idText)
|> Option.defaultValue (FSComp.SR.csOverloadCandidateIndexedArgumentTypeMismatch ((snd x.calledArg.Position) + 1))
|> Option.defaultValue (FSComp.SR.csOverloadCandidateIndexedArgumentTypeMismatch ((Lib.vsnd x.calledArg.Position) + 1)) //snd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we always be qualified with Lib? Is that how other functions from Lib are called elsewhere?

@KevinRansom KevinRansom merged commit 13aaaef into dotnet:master May 27, 2020
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Feb 23, 2021
* MakeCalledArgs allocates a struct tuple

* Add vsnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants