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

Do not generate unique __Field for each struct #2564

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Mingun
Copy link
Contributor

@Mingun Mingun commented Aug 10, 2023

As suggested in #2250 (review), this PR replaces __Field generation with common structs inside serde crate.

There are three different forms of a __Field struct, each one has its own struct:

  • Field + FieldSeed -- for structs without flatten fields and without #[serde(deny_unknown_fields)]
  • FieldStrong + FieldStrongSeed -- for structs without flatten fields and with #[serde(deny_unknown_fields)]
  • FieldFlatten + FieldFlattenSeed -- for structs with flatten fields

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thanks for the PR — this will be useful for benchmarking. Could you please look into compile time impact and runtime impact on https://github.com/serde-rs/json-benchmark, and compile time on https://github.com/gluon-lang/lsp-types?

I am not going to merge this though. I am not on board with exposing public Field/FieldStrong right away, and I am not on board with derive for simple structs needing to use __private in a way that users cannot copy into their handwritten impls. This is discussed in the review you linked, with a recommendation for a path forward.

@Mingun Mingun force-pushed the common-field branch 7 times, most recently from d7322e6 to df12e82 Compare August 11, 2023 20:47
@Mingun
Copy link
Contributor Author

Mingun commented Aug 11, 2023

Here is some results: comparison.zip.

Measured commits v1.0.183 (05a5b7e) and df12e82, which removes all possible variants of __Field for struct field names and __Field for representing variants of externally tagged enums.

In both cases serde was injected using [patch] section in root Cargo.toml of both projects:

[patch.crates-io]
serde = { path = "../serde/serde" }

The following commands was used (taken from this comment):

  • json-benchmark:
    cargo clean
    $env:CARGO_INCREMENTAL=0; cargo check --timings --no-default-features --features all-files,parse-struct,lib-serde
    cargo clean
    $env:CARGO_INCREMENTAL=0; cargo build --timings --release --no-default-features --features all-files,parse-struct,lib-serde
    PR is about 0.3 sec. faster on checking / building of json-benchmark lib itself. native jemalloc library was not found on my machine, so I cannot provide runtime impact right now
  • lsp-types:
    cargo clean
    $env:CARGO_INCREMENTAL=0; cargo check --timings
    cargo clean
    $env:CARGO_INCREMENTAL=0; cargo build --timings
    PR is about 3 sec. faster on checking / building of lsp-types itself

@nnethercote perhaps you are willing to test impact of this PR on your cases?

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