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

Remove explicit ContentDeserializer construction in visit functions #2822

Merged
merged 1 commit into from
Sep 7, 2024

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Sep 7, 2024

This is a good suggestion from #2821 (review). I was not able to measure any binary size improvement — the rlib is 111K before and after. But it's worth making the change.

@dtolnay dtolnay mentioned this pull request Sep 7, 2024
@@ -1715,16 +1717,10 @@ mod content {
V: Visitor<'de>,
E: de::Error,
{
fn content_ref_deserializer_pair<'a, 'de, E>(
fn content_ref_deserializer_pair<'a, 'de>(
Copy link
Member Author

Choose a reason for hiding this comment

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

I also tried adding:

impl<'a, A, B> Pair for &'a (A, B) {
    type First = &'a A;
    type Second = &'a B;
    fn split(self) -> (&'a A, &'a B) {
        (&self.0, &self.1)
    }
}

to make this function go away, like in the visit_content_map case. See #2823.

But somehow that made the rlib go back up from 111K to 124K, negating the benefit from #2821. I do not fully understand why this happens.

@dtolnay dtolnay merged commit 4487cb2 into serde-rs:master Sep 7, 2024
30 checks passed
@dtolnay dtolnay deleted the mapcontentdeserializer branch September 7, 2024 23:41
@Mingun
Copy link
Contributor

Mingun commented Sep 8, 2024

If you are worried about the size of the generated code, then maybe merge

I rebased both PRs on current master for easing of testing.

@Mingun
Copy link
Contributor

Mingun commented Sep 9, 2024

Some tests on my computer (the same test library project as in #2821):

Commit Size (bytes) Diff from master (bytes)
master 143694
visitor-driven 152842 +9148
common-field 136930 -6764
both 142462 -1232

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

Successfully merging this pull request may close these issues.

2 participants