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

Implement GATs #231

Merged
merged 2 commits into from
Nov 11, 2022
Merged

Implement GATs #231

merged 2 commits into from
Nov 11, 2022

Conversation

richard-uk1
Copy link
Collaborator

The main gain from this is being able to iterate over BezPaths without cloning. Makes MSRV 1.65

I think what we do now is clearer.

fn path_elements(&self, _tolerance: f64) -> Self::PathElementsIter {
self.0.clone().into_iter()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the main benefit from this PR - now we don't have to clone the whole object.

Copy link

@Zarenor Zarenor left a comment

Choose a reason for hiding this comment

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

Excited to see this move, now that GATs are stable!

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

One QQ, but otherwise very neat to see how simple a change this is!

fn path_elements(&self, _tolerance: f64) -> Self::PathElementsIter {
self.0.clone().into_iter()
fn path_elements(&self, _tolerance: f64) -> Self::PathElementsIter<'_> {
self.0.iter().copied()
Copy link
Member

Choose a reason for hiding this comment

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

so the question I have with all of these is basically: do we even bother with copy? We we need to?

Copy link
Collaborator Author

@richard-uk1 richard-uk1 Nov 7, 2022

Choose a reason for hiding this comment

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

Do you mean "why do we copy the elements rather than returning a ref to them?" If so then the answer is because some impls of path_elements will create the path elements on-demand, and so need to pass ownership of them to the callee.

If I've misunderstood let me know.

Copy link
Member

Choose a reason for hiding this comment

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

Right, that answers my question. LGTM!

Copy link
Collaborator Author

@richard-uk1 richard-uk1 Nov 8, 2022

Choose a reason for hiding this comment

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

I think it's an important question. From a rough calculation, the size of PathEl is around 50 bytes - not insignificant!

Calc: Point = 2 x f64 = 16 bytes, PathEl = 3 x Point + u8 (discriminant) = 49 ~ 50.

Having said that if your cache-line is 64 bytes you're still in budget, even with an 8 byte discriminant.

Copy link
Member

Choose a reason for hiding this comment

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

yea, if we could return them by reference it would be nice, but it is understandable if we can't. Unless GATs let us do a thing where the current element is owned by the iterator, and lent out? Is that now expressible? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Measurement is important but I strongly suspect that the optimizer will eliminate these copies.

@richard-uk1
Copy link
Collaborator Author

richard-uk1 commented Nov 8, 2022 via email

@richard-uk1
Copy link
Collaborator Author

I've investigated doing benchmarks with criterion.rs, and I think it's really great! But it's quite involved setting it up, so I will merge this PR for now.

@richard-uk1 richard-uk1 merged commit 79e5787 into linebender:master Nov 11, 2022
@richard-uk1 richard-uk1 deleted the gats branch November 17, 2022 21:17
simoncozens added a commit to simoncozens/kurbopy that referenced this pull request Mar 13, 2023
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.

4 participants