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

perf: Speed up compile times with nom #402

Merged
merged 1 commit into from Dec 23, 2022
Merged

perf: Speed up compile times with nom #402

merged 1 commit into from Dec 23, 2022

Conversation

epage
Copy link
Member

@epage epage commented Dec 23, 2022

This is using a short-lived fork nom until we can get the changes upstreamed. Note that combine requires using attempt to backtrack while nom backtracks by default and requires cut to not backtrack.

I find the straight functions much easier to understand what is happening and this allows us to intermix procedural with declarative logic (e.g. in string processing I skipped combinators to make it easier to not require an allocation).

Regarding that allocation, we still do it but this opens the door for us to use InternalString for user values which might give us more of a performance boost (previously, the forced allocation made it a moot point to measure it).

Running cargo clean -p toml_edit && time cargo check, I get 3s for building toml_edit with combine and 0.5s for nom.

For runtime performance

  • Parsing cargo inits generated manifest took 4% less time
  • Parsing cargos manifest took 2% less time
  • 10 tables took 37% less time
  • 100 tables took 41% less time
  • Array of 10 tables took 38% less time
  • Array of 100 tables took 40% less time

(some of this might be because we use dispatch more than before and some because our error reporting is less allocation heavy)

This is with Rust 1.66 on a i9-12900H processor under WSL2

Fixes #327

This is using a short-lived fork `nom` until we can get the changes
upstreamed.  Note that `combine` requires using `attempt` to backtrack
while `nom` backtracks by default and requires `cut` to not backtrack.

I find the straight functions much easier to understand what is
happening and this allows us to intermix procedural with declarative
logic (e.g. in string processing I skipped combinators to make it easier
to not require an allocation).

Regarding that allocation, we still do it but this opens the door for us
to use `InternalString` for user values which might give us more of a
performance boost (previously, the forced allocation made it a moot
point to measure it).

Running `cargo clean -p toml_edit && time cargo check`, I get 3s for building `toml_edit` with `combine` and 0.5s for `nom`.

For runtime performance
- Parsing `cargo init`s generated manifest took 4% less time
- Parsing `cargo`s manifest took 2% less time
- 10 tables took 37% less time
- 100 tables took 41% less time
- Array of 10 tables took 38% less time
- Array of 100 tables took 40% less time

This is with Rust 1.66 on a i9-12900H processor under WSL2

Fixes toml-rs#327
@epage
Copy link
Member Author

epage commented Dec 23, 2022

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.

toml_edit is pretty slow to compile
1 participant