Skip to content

fix(schema): Improve deserialization errors and performance - #17697

Merged
rustbot merged 4 commits into
rust-lang:masterfrom
epage:anydep
Nov 7, 2026
Merged

rustbot merged 4 commits into
rust-lang:masterfrom
epage:anydep

Conversation

@epage

@epage epage commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

What does this PR try to resolve?

This reduces Tokio manifest parse and deserialization time by 19.4%, from 130.1 µs to 104.9 µs.

This also improves the error quality, removing blank lines and being more specific in spans

Notes to reviewers

Had been meaning to write an alternative serde-untagged to help with this but decided to stop waiting for "one day".

I benchmarked Tokio's published Cargo.toml because

  • It covers a lot of different cases
  • It is in the format most parsed manifests will be in

🤖 LLM involvement: filling in Deserialize branches

epage added 4 commits November 4, 2026 20:45
Be a bit more scientific than measuring end-to-end through profiling
tracing.

I chose tokio because it is one of the larger ones and represents a lot
of functionality.

I chose from a `.crate` because we are likely to parse orders of
magnitude more of those than hand written ones.
…itor for maps

It buffers the map, slowing things down and reducing error quality.

One day I'd like to implement an alternative that addresses these gaps
but better to just skip it for now.

Tokio’s published manifest took 11.5% less time to parse+deserialize, from 123.7 µs to 109.4 µs.
That it was that noticeable despite TOML's parse overhead says
something.
…ween deserialize cases

This reduced Tokio manifest parse+deserialization time by 8.5% relative to its parent, from 116.4 µs to 106.5 µs.
Yeah, that "before" doesn't fully align with the previous commit.
The joy of jitter
Mostly to reduce false positives when looking for usage patterns similar
to `serde_value`.
@rustbot rustbot added A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 6, 2026
@rustbot

rustbot commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

r? @Muscraft

rustbot has assigned @Muscraft.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Muscraft, @epage, @weihanglo
  • @Muscraft, @epage, @weihanglo expanded to Muscraft, epage, weihanglo
  • Random selection from Muscraft, weihanglo

@0xPoe 0xPoe left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@0xPoe
0xPoe added this pull request to the merge queue Nov 7, 2026
@weihanglo
weihanglo removed this pull request from the merge queue due to a manual request Nov 7, 2026
workspace = true

[dev-dependencies]
divan.workspace = true

@weihanglo weihanglo Nov 6, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(not blocking) we have criterion already. Should we migrate the rest?

criterion = { version = "0.8.2", features = ["html_reports"] }

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I always forget about our benchmarks. I'd be up for transitioning in a follow up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[ERROR] invalid character ` ` in registry name: `bad name`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
--> Cargo.toml:8:17
|
8 | [dependencies.bar]

@weihanglo weihanglo Nov 6, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Huh! I didn't know we have this buggy error message. Thanks!

View changes since the review

Comment thread src/context/schema.rs

@weihanglo weihanglo Nov 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This fails with the PR, but previously it passes. Is it expected? And can we track the behavior change somewhere?

(I guess that was due to that we consolidate manifest deserialization)

#[cargo_test]
fn unused_keys() {
    let p = project()
        .file(
            "Cargo.toml",
            r#"
            [workspace]
            members = ["bar"]

            [workspace.dependencies]
            bar = { path = "bar" }

            [package]
            name = "foo"
            edition = "2024"

            [dependencies]
            bar = { workspace = true, version = 1 }
            "#,
        )
        .file("src/lib.rs", "use bar as _;")
        .file("bar/Cargo.toml", &cargo_test_support::basic_manifest("bar", "0.0.0"))
        .file("bar/src/lib.rs", "")
        .build();
    p.cargo("check")
        .with_status(101)
        .with_stderr_data(str![[r#"
[ERROR] invalid type: integer `1`, expected a string
  --> Cargo.toml:13:49
   |
13 |             bar = { workspace = true, version = 1 }
   |                                                 ^

"#]])
        .run();
}

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In contrast, bar = { workspace = true, version = "1" } still get the unused key warning, so it is more about those are deserialized more aggresively.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good point. I also asked my agent to search GitHub for a case that this change could break, but we didn't find one. It is still good to call this out and let people know about the behavior change. Thank you!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The other similar case:

[workspace.dependencies]
bar = { path = "bar", workspace = false }

the workspace = false used to be a unused key warning now turns into a hard error. This is definitely the right move, though I guess we might want to capture this in tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, forgot to call this out in the PR description.

Unsure about others but I view unused manifest key warnings as a "future incompat" warning: it is carve out that let's us add new fields without breaking compatibility. So in this case, I'm not too concerned about breaking people.

As for tests, I tend to view those as prescriptive of intended behavior. This feels like an area of unspecified behavior where the test would be descriptive of how Cargo currently behaves which has me hesitate about having a test for it though I am open to thoughts on the role of tests and how to message these tests to make their intent clear.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. That sounds reasonable. Given Dongpo has did a ecosystem scan already. I think we are good to go. Thanks for the patch and the review, folks. I like it very much!

@weihanglo weihanglo left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread src/context/schema.rs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. That sounds reasonable. Given Dongpo has did a ecosystem scan already. I think we are good to go. Thanks for the patch and the review, folks. I like it very much!

@rustbot
rustbot added this pull request to the merge queue Nov 7, 2026
Merged via the queue into rust-lang:master with commit c82e769 Nov 7, 2026
32 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 7, 2026
@epage
epage deleted the anydep branch November 7, 2026 23:44
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-rust-lang__cargo that referenced this pull request Nov 8, 2026
This is a follow up to rust-lang#17697 which introduced divan.
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-rust-lang__cargo that referenced this pull request Nov 8, 2026
### What does this PR try to resolve?

Get us on a consistent benchmarking library with cleanups from the new
API

### Notes to reviewers

This is a follow up to
rust-lang#17697 (comment)

---

🤖 LLM involvement: prototyping and handling trivial code transformations
epage added a commit to epage/cargo that referenced this pull request Nov 9, 2026
…make

This is a follow up to rust-lang#17697 that clarifies the bench names and adds
additional benches in prep for experimenting with other optimizations like
- Avoiding `make_owned` like in rust-lang#17296
- Caching in alternative formats
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-rust-lang__cargo that referenced this pull request Nov 9, 2026
…rust-lang#17701)

### What does this PR try to resolve?

This takes manifest parse time from 113us
(`de_table_parse_make_owned_deserialize_tokio`) to 105us
(`de_table_parse_deserialize_tokio` which is the same as
`toml_from_str_tokio`).

Any diagnostic that needs the TOML format is affected which is lints but
those are all scoped to local anyways.

### Notes to reviewers

This supersedes rust-lang#17296.
Unsure how it got closed.
Compared to that
- We trigger purely off of local (path) vs not which is the same
  decision made for most lints
- No tests were added since they weren't adding much value
- The code is simpler while doing the same thing

Bench changes is a follow up to rust-lang#17697 which was only focused on
`toml_from_str_tokio` which wasn't a full representation of what we're
doing there.
This is also to leave room for other benches like exploring cached
parses of manifests in formats that are faster to parse than TOML.

---

🤖 LLM involvement: experimentation
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Nov 11, 2026
Update cargo submodule

15 commits in c07ac2c4d12237effc4b94f4543769b421790045..ede6cefea9731cb595942338824c2f9a610b8189
2026-11-06 19:13:29 +0000 to 2026-11-11 12:33:16 +0000
- chore: bump to 0.103.0; update changelog (rust-lang/cargo#17709)
- Update documentation about adding new publishable crates (rust-lang/cargo#17711)
- test: Make cross compile test work with annotate-snippets whitespace changes (rust-lang/cargo#17707)
- feat(config): Expose config merging, reading, and schemas in a crate (rust-lang/cargo#17705)
- feat(schema): Expose SBOM types (rust-lang/cargo#17683)
- fix: strip host deps whose debuginfo was weakened already (rust-lang/cargo#17691)
- fix: dont strip if any transtive dep has debuginfo on  (rust-lang/cargo#17689)
- Reduce memory allocation in crate_type.rs (rust-lang/cargo#17706)
- fix(doc): do not suggest cargo fix for rustdoc warnings (rust-lang/cargo#17702)
- perf(parse): Trade remote manifest diagnostic quality for performance (rust-lang/cargo#17701)
- refactor(config): Pull deserialiation into the config layer (rust-lang/cargo#17699)
- Use trusted publishing for the home crate (rust-lang/cargo#17703)
- refactor(benchsuite): Port to divan (rust-lang/cargo#17700)
- fix(schema): Improve deserialization errors and performance (rust-lang/cargo#17697)
- fix(lockfile): sort unused patches in Cargo.lock (rust-lang/cargo#17698)
@rustbot rustbot added this to the 1.102.0 milestone Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-manifest Area: Cargo.toml issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants