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

Use smallvec for message arguments #268

Closed
wants to merge 11 commits into from

Conversation

newpavlov
Copy link
Contributor

Closes #249

Unfortunately it's a backwards incompatible change, at lease for wayland-commons and probably for other crates which use it in public API.

Maybe use this chance to update to 2018 edition?

@codecov
Copy link

codecov bot commented Jun 23, 2019

Codecov Report

Merging #268 into master will decrease coverage by 0.04%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #268      +/-   ##
==========================================
- Coverage   82.79%   82.75%   -0.05%     
==========================================
  Files          48       48              
  Lines        4604     4604              
==========================================
- Hits         3812     3810       -2     
- Misses        792      794       +2
Flag Coverage Δ
#both_native 81.69% <88.88%> (-0.07%) ⬇️
#client_native 83.78% <92.85%> (-0.06%) ⬇️
#full_rust 84.4% <92.85%> (-0.06%) ⬇️
#server_native 82.55% <88.88%> (-0.06%) ⬇️
Impacted Files Coverage Δ
wayland-protocols/src/lib.rs 0% <ø> (ø) ⬆️
wayland-commons/src/lib.rs 0% <ø> (ø) ⬆️
wayland-client/src/lib.rs 57.14% <ø> (ø) ⬆️
wayland-scanner/src/common_gen.rs 94.01% <ø> (ø) ⬆️
wayland-server/src/lib.rs 25% <ø> (ø) ⬆️
wayland-server/src/rust_imp/clients.rs 86.85% <100%> (ø) ⬆️
wayland-commons/src/socket.rs 93.53% <100%> (-0.69%) ⬇️
wayland-server/src/rust_imp/globals.rs 92.14% <100%> (ø) ⬆️
wayland-commons/src/wire.rs 74.61% <66.66%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4be4af...06146f7. Read the comment docs.

@newpavlov
Copy link
Contributor Author

newpavlov commented Jun 23, 2019

I am not sure why Rust 1.21 tests fail, smallvec should have MSRV equal to 1.20.

@elinorbgr
Copy link
Member

On principle I approve this PR 👍 , we just need to figure out why rust 1.21 fails. Looks like the generated scanner code has an issue somehow, unfortunately travis truncated the log, so this will need to be run locally.

Given this is going to be a breaking change, and with the possibility of going to rust 2018, this will likely happen, but I need to decide a few things, depending on if / how I want to address #189. So I'll likely let this PR sit a few days while I decide the path I want to take.

@newpavlov
Copy link
Contributor Author

For now I've bumped MSRV to 1.24, which is required by lazycell v1.2, and looks like it fixes the problem.

@elinorbgr
Copy link
Member

Okay so, it has been quite more than a few days, but now I have a clearer idea.

#271 is nearly finished and will be some enormous breaking change, so this can be integrated with it.

Do you want to rebase your PR once I've landed #271, or shall I manually integrate your changes #271 ?

@elinorbgr
Copy link
Member

Thinking back about this, I have one slight source of uneasiness: this would make smallvec part of the public API of wayland-commons, which I'm reluctant to do given it does not look like smallvec will go 1.0 soon.

elinorbgr added a commit that referenced this pull request Sep 11, 2019
Any message with 4 argument or less will have these arguments stored
inline rather than in an heap-allocated vec.

The number 4 was chose because almost all messages have 4 arguments
or less, and some potentially very spammy messages (wl_touch.move)
have exactly 4 arguments. Avoiding allocations in these cases should
generally be a gain.

Moreother, to avoid bloating the size of Message due to this,
String and Array arguments are further boxed, reducing the size
of Argument from 4*usize to 2*usize. These kind of arguments are
generally pretty rare, so the double allocation should overall not
counter the size gain.

Closes #268, #249
elinorbgr added a commit that referenced this pull request Sep 11, 2019
Any message with 4 argument or less will have these arguments stored
inline rather than in an heap-allocated vec.

The number 4 was chose because almost all messages have 4 arguments
or less, and some potentially very spammy messages (wl_touch.move)
have exactly 4 arguments. Avoiding allocations in these cases should
generally be a gain.

Moreother, to avoid bloating the size of Message due to this,
String and Array arguments are further boxed, reducing the size
of Argument from 4*usize to 2*usize. These kind of arguments are
generally pretty rare, so the double allocation should overall not
counter the size gain.

Closes #268, #249
elinorbgr added a commit that referenced this pull request Sep 12, 2019
Any message with 4 argument or less will have these arguments stored
inline rather than in an heap-allocated vec.

The number 4 was chose because almost all messages have 4 arguments
or less, and some potentially very spammy messages (wl_touch.move)
have exactly 4 arguments. Avoiding allocations in these cases should
generally be a gain.

Moreother, to avoid bloating the size of Message due to this,
String and Array arguments are further boxed, reducing the size
of Argument from 4*usize to 2*usize. These kind of arguments are
generally pretty rare, so the double allocation should overall not
counter the size gain.

Closes #268, #249
elinorbgr added a commit that referenced this pull request Sep 12, 2019
Any message with 4 argument or less will have these arguments stored
inline rather than in an heap-allocated vec.

The number 4 was chose because almost all messages have 4 arguments
or less, and some potentially very spammy messages (wl_touch.move)
have exactly 4 arguments. Avoiding allocations in these cases should
generally be a gain.

Moreother, to avoid bloating the size of Message due to this,
String and Array arguments are further boxed, reducing the size
of Argument from 4*usize to 2*usize. These kind of arguments are
generally pretty rare, so the double allocation should overall not
counter the size gain.

Closes #268, #249
@newpavlov
Copy link
Contributor Author

newpavlov commented Sep 12, 2019

it does not look like smallvec will go 1.0 soon

Do you plan to release v1.0 versions in a near future? smallvec didn't have breaking releases for almost 2 years (v0.6.0 was released on 2017-12-01). I think the main reasons why they do not release v1.0 is that they wait for const generics.

Even if you don't think that wayland-rs should not use smallvec right now, I believe it's worth to at least create an issue for that.

UPD: Relevant issue: servo/rust-smallvec#73. Citing it:

I think we should consider making a 1.0 release in the near future (sometime this year)

UPD2: Ah, I haven't noticed #273.

@elinorbgr
Copy link
Member

elinorbgr commented Sep 12, 2019

Yes, I've integrated it in #273. Did it in a way so minimize the API impact of upgrading smallvec : the code generated by wayland-scanner directly uses the smallvec re-exported by wayland-commons. So people using wayland-rs with their own wayland extensions should not have any issue with updates.

EDIT: also yes, I'm hoping to release a 1.0 in the nearish future, if no big issues are found with the 0.24 API.

@newpavlov newpavlov deleted the smallvec branch September 12, 2019 17:12
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.

Message type optimizations
2 participants