Skip to content

Remove explicit ContentDeserializer construction in visit functions#2822

Merged
dtolnay merged 1 commit into
serde-rs:masterfrom
dtolnay:mapcontentdeserializer
Sep 7, 2024
Merged

Remove explicit ContentDeserializer construction in visit functions#2822
dtolnay merged 1 commit into
serde-rs:masterfrom
dtolnay:mapcontentdeserializer

Conversation

@dtolnay

@dtolnay dtolnay commented Sep 7, 2024

Copy link
Copy Markdown
Member

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
Comment thread serde/src/private/de.rs
E: de::Error,
{
fn content_ref_deserializer_pair<'a, 'de, E>(
fn content_ref_deserializer_pair<'a, 'de>(

Copy link
Copy Markdown
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
@dtolnay dtolnay deleted the mapcontentdeserializer branch September 7, 2024 23:41
@Mingun

Mingun commented Sep 8, 2024

Copy link
Copy Markdown
Contributor

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

Mingun commented Sep 9, 2024

Copy link
Copy Markdown
Contributor

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