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

Pass shared PietText by ref instead of cloning #1205

Merged
merged 1 commit into from
Sep 9, 2020
Merged

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Sep 9, 2020

Currently we create a copy of the PietText object every time we
need one. This changes that so that there is a single instance
in the ContextState, and the various contexts just pass out
a reference to this object as needed.

This should have few practical implications, except that in
trees with lots of text we will save a few microseconds. It's
mostly an API improvement, since the methods that tend to use
a PietText object generally want it passed by ref anyway.

Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

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

Yes, looks good. When you say a few microseconds, did you measure that?

In theory, switching to &mut might break something, but in practice I think it's a cleaner type. It's causing flashbacks to the early days of xi-win, where it was a bit of a struggle to get the lifetimes right when rebuilding resources (tons of cloning of these factories), but I think generally the current state is right.

@cmyr
Copy link
Member Author

cmyr commented Sep 9, 2020

no, microseconds was just me mentally multiplying the cost of cloning an arc by a few hundred text objects.

@raphlinus
Copy link
Contributor

Yeah, the new changes reflect breakage I would have expected, but it doesn't seem bad at all to fix them. +1

Base automatically changed from remove-old-text-type to master September 9, 2020 17:28
Currently we create a copy of the PietText object every time we
need one. This changes that so that there is a single instance
in the ContextState, and the various contexts just pass out
a reference to this object as needed.

This should have few practical implications, except that in
trees with lots of text we will save a few microseconds. It's
mostly an API improvement, since the methods that tend to use
a PietText object generally want it passed by ref anyway.
@cmyr cmyr merged commit f04a4c5 into master Sep 9, 2020
@cmyr cmyr deleted the pass-text-by-ref branch September 9, 2020 20:02
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.

2 participants