Skip to content

feat(toml)!: Replace toml_edit with toml_parse#945

Merged
epage merged 9 commits intotoml-rs:mainfrom
epage:de
Jun 12, 2025
Merged

feat(toml)!: Replace toml_edit with toml_parse#945
epage merged 9 commits intotoml-rs:mainfrom
epage:de

Conversation

@epage
Copy link
Member

@epage epage commented Jun 12, 2025

This adds toml::de::DeTable, toml::de::DeValue, toml::de::DeString, and toml::de::DeArray which are borrowed, spanned data structures for parsing into that we then support deserializing from. Due to the nature of TOML (a Maps keys are intermixed with descendant and parent Map keys through dotted keys, standard table ordering, error reporting requirements), we can't directly deserialize from the parsed result.

This also adds IntoDeserializer for Deserializer / ValueDeserializer.

BREAKING CHANGE: ValueDeserializer::new was replaced with
ValueDeserializer::parse and can return an error.

BREAKING CHANGE: Deserialize::new was replaced with
Deserializer::parse and can return an error.

For the porting of toml_edit to toml_parse, see #922

For the introduction of toml_parse, see #891

Benchmarks

Notes:

  • A big difference between v0.8.23 and main is refactor(edit): Switch to toml_parse #922
  • preserve_order only affected toml::Table, so the older "document" benchmarks for toml will parse into an IndexMap (from toml_edit) and then deserialize into either a BTreeMap or an IndexMap while de will parse and deserialize into either a BTreeMap or an IndexMap
  • manifest deserializes into a struct, avoiding at least a top-level *Map creation and avoid allocations of some keys.

0_cargo::toml::document::2-features

parser features time
v0.5 1032us
v0.5 preserve_order 924us
v0.8.23 745us
main 697us
main preserve_order 589us
de 702us
de preserve_order 464us
de unsafe 706us
de simd 702us
de all 459us

0_cargo::toml::manifest::2-features

parser features time
v0.5 921us
v0.5 preserve_order 896us
v0.8.23 644us
main 590us
main preserve_order 593us
de 580us
de preserve_order 445us
de unsafe 581us
de simd 581us
de all 439us

1_map::toml::document::100

parser features time
v0.5 99us
v0.5 preserve_order 100us
v0.8.23 74us
main 57us
main preserve_order 58us
de 38us
de preserve_order 40us
de unsafe 37us
de simd 39us
de all 40us

1_map::toml::document::100

parser features time
v0.5 76us
v0.5 preserve_order 81us
v0.8.23 66us
main 45us
main preserve_order 48us
de 25us
de preserve_order 34us
de unsafe 26us
de simd 26us
de all 34us

@epage epage marked this pull request as draft June 12, 2025 15:35
epage added 9 commits June 12, 2025 12:12
This changes out `Deserializer` and `ValueDeserializer` with ones built
on `DeTable` and `DeValue`, rather than `toml_edit`

This adds `IntoDeserializer` for both.

BREAKING CHANGE: `ValueDeserializer::new` was replaced with
`ValueDeserializer::parse`

BREAKING CHANGE: `Deserialize::new` was replaced with
`Deserializer::parse`
@epage epage force-pushed the de branch 2 times, most recently from e438cca to 9af2239 Compare June 12, 2025 17:25
@epage epage marked this pull request as ready for review June 12, 2025 17:27
@epage
Copy link
Member Author

epage commented Jun 12, 2025

Not controlling for jitter:

$ cargo bench -Fpreserve_order --bench 0-cargo -- 2-features
0_cargo              fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ serde_json                      │               │               │               │         │
│  ├─ document                     │               │               │               │         │
│  │  ╰─ 2-features  159 µs        │ 275.1 µs      │ 170.7 µs      │ 175.1 µs      │ 100     │ 100
│  ╰─ manifest                     │               │               │               │         │
│     ╰─ 2-features  169.8 µs      │ 236.6 µs      │ 188.1 µs      │ 192.8 µs      │ 100     │ 100
├─ toml_parse                      │               │               │               │         │
│  ├─ tokens                       │               │               │               │         │
│  │  ╰─ 2-features  83.09 µs      │ 93.21 µs      │ 84.86 µs      │ 85.44 µs      │ 100     │ 100
│  ├─ events                       │               │               │               │         │
│  │  ╰─ 2-features  116 µs        │ 130.6 µs      │ 121.1 µs      │ 120 µs        │ 100     │ 100
│  ╰─ decoded                      │               │               │               │         │
│     ╰─ 2-features  172.1 µs      │ 236.1 µs      │ 180.1 µs      │ 180.8 µs      │ 100     │ 100
├─ toml                            │               │               │               │         │
│  ├─ detable                      │               │               │               │         │
│  │  ╰─ 2-features  326.9 µs      │ 621.7 µs      │ 339.5 µs      │ 343.8 µs      │ 100     │ 100
│  ├─ detable_owned                │               │               │               │         │
│  │  ╰─ 2-features  443.4 µs      │ 513.9 µs      │ 456.1 µs      │ 457.9 µs      │ 100     │ 100
│  ├─ document                     │               │               │               │         │
│  │  ╰─ 2-features  562.1 µs      │ 633.6 µs      │ 580.9 µs      │ 582.9 µs      │ 100     │ 100
│  ╰─ manifest                     │               │               │               │         │
│     ╰─ 2-features  465.1 µs      │ 662.3 µs      │ 546.1 µs      │ 538.8 µs      │ 100     │ 100
├─ toml_edit                       │               │               │               │         │
│  ├─ document                     │               │               │               │         │
│  │  ╰─ 2-features  622 µs        │ 897.2 µs      │ 694.6 µs      │ 702.1 µs      │ 100     │ 100
│  ╰─ manifest                     │               │               │               │         │
│     ╰─ 2-features  814.9 µs      │ 910.2 µs      │ 841.2 µs      │ 845.4 µs      │ 100     │ 100
╰─ toml_v05                        │               │               │               │         │
   ├─ document                     │               │               │               │         │
   │  ╰─ 2-features  943.4 µs      │ 1.083 ms      │ 990.7 µs      │ 990.6 µs      │ 100     │ 100
   ╰─ manifest                     │               │               │               │         │
      ╰─ 2-features  890.3 µs      │ 1.499 ms      │ 982.2 µs      │ 995.7 µs      │ 100     │ 100

@epage epage merged commit 8f7824f into toml-rs:main Jun 12, 2025
17 checks passed
@epage epage deleted the de branch June 12, 2025 17:37
joshtriplett added a commit to joshtriplett/toml that referenced this pull request Jun 12, 2025
Also point people towards "unsafe" if they want maximum performance (per
toml-rs#945 showing that the features
together have better performance than "perf" alone).
@coveralls
Copy link

coveralls commented Jun 12, 2025

Pull Request Test Coverage Report for Build 15617146449

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 734 of 1190 (61.68%) changed or added relevant lines in 22 files are covered.
  • 7 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.9%) to 69.416%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/toml/src/value.rs 1 3 33.33%
crates/toml/src/de/datetime.rs 8 12 66.67%
crates/toml/src/de/parser/mod.rs 18 22 81.82%
crates/toml/src/de/array.rs 12 19 63.16%
crates/toml/src/de/spanned.rs 20 27 74.07%
crates/toml/src/de/error.rs 90 98 91.84%
crates/toml/src/de/parser/debug.rs 0 9 0.0%
crates/toml/src/de/detable.rs 7 18 38.89%
crates/toml/src/de/value.rs 56 68 82.35%
crates/toml/src/de/key.rs 16 33 48.48%
Files with Coverage Reduction New Missed Lines %
crates/toml_edit/src/error.rs 1 91.0%
crates/toml/src/value.rs 1 62.18%
crates/toml_edit/src/de/value.rs 2 78.95%
crates/toml_edit/src/de/error.rs 3 76.19%
Totals Coverage Status
Change from base Build 15616989066: -0.9%
Covered Lines: 6185
Relevant Lines: 8910

💛 - Coveralls

joshtriplett added a commit to joshtriplett/toml that referenced this pull request Jun 13, 2025
Also point people towards "unsafe" if they want maximum performance (per
toml-rs#945 showing that the features
together have better performance than "perf" alone).
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.

2 participants