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

Fixes #3460. xxxtoxxx consistency #3461

Merged
merged 13 commits into from May 11, 2024

Conversation

tig
Copy link
Collaborator

@tig tig commented May 8, 2024

Fixes

Proposed Changes/Todos

  • ScreenToFrame -> takes Point
  • ScreenToViewport -> takes Point

@dodexahedron
Copy link
Collaborator

Hey quick easy optiization:

Make them take it as in, too, so reference can be passed by default without needing to be explicitly done at the callsite.

@dodexahedron
Copy link
Collaborator

That, by the way, is just a good habit to get into when passing structs - especially blittable ones.

@dodexahedron
Copy link
Collaborator

For certain other cases, there's also now ref readonly for method parameters, in c# 12, but that is slightly different. MS has a matrix somewhere showing the effects and compatibility at the callsite for ref, ref readonly, in, and out, for the curious. I think it's linked from the what's new for c# 12.

@tig
Copy link
Collaborator Author

tig commented May 8, 2024

in -> done.

@dodexahedron
Copy link
Collaborator

dodexahedron commented May 9, 2024

Hm. Why building new points in a lot of those lines rather than just passing the point itself?

At the first place in a method that assigns it to something, it'll still get value copied anyway.

And with a non-referenceable ephemeral new() in a method call, it will be copied twice, making the in not apply.

Copy link
Collaborator

@dodexahedron dodexahedron left a comment

Choose a reason for hiding this comment

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

Mostly same minor comments elsewhere, so I won't repeat it all over the place.

Since consistency was the theme for this one anyway, using Offset when offsetting points is probably a good idea, and can also result in less copy activity and more inlining.

The ephemeral constructor stuff, though, is potentially tangible with how hot those code paths are.

Otherwise, YAY!

Terminal.Gui/Application.cs Outdated Show resolved Hide resolved
Terminal.Gui/View/Adornment/Border.cs Outdated Show resolved Hide resolved
Terminal.Gui/View/Layout/ViewLayout.cs Show resolved Hide resolved
@dodexahedron
Copy link
Collaborator

dodexahedron commented May 9, 2024

There's also an Offset overload that takes Point, too, which is better when you already have one.

Low-level performance stuff relevant here and other hot paths

In the case of the Point struct or other blittable structs like it, especially, it's better to pass one of it, whether by value or reference, than to pass components in multiple parameters. It's an 8-byte wide struct, which can fit in one register if sent by itself, whereas 2 ints is two copies in separate registers plus a non-obvious amount of other work at the CIL level and internally in native code.

Plus, consistency of the internal layouts of our types also means less of the deconstruction and reconstruction work at boundaries.

Man, github, pick a lane: Markdown or HTML. 😆

@tig
Copy link
Collaborator Author

tig commented May 9, 2024

Hm. Why building new points in a lot of those lines rather than just passing the point itself?

You mean in the tests?

At the first place in a method that assigns it to something, it'll still get value copied anyway.

And with a non-referenceable ephemeral new() in a method call, it will be copied twice, making the in not apply.

I was focused on getting the API right; perf next.

image

How do you suggest I address this?

@tig
Copy link
Collaborator Author

tig commented May 9, 2024

I bit the bullet and changed MouseEvent to use Point.

@dodexahedron
Copy link
Collaborator

Sounds like it's probably pretty great.

I'm only half awake after a wrong number caller woke me up, so I'm useless for review right now but I'll get on that as soon as I'm up and running tomorrow. :)

@tig tig merged commit 6c6dec1 into gui-cs:v2_develop May 11, 2024
1 check passed
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.

None yet

2 participants