Sha256: 115b636769c307bd80ecc5b89ffad47877352bc93ef47bf664093d3d7a2562cc

Contents?: true

Size: 1.83 KB

Versions: 13

Compression:

Stored size: 1.83 KB

Contents

//! # Performance
//!
//! ## Runtime Performance
//!
//! See also the general Rust [Performance Book](https://nnethercote.github.io/perf-book/)
//!
//! Tips
//! - Try `cargo add winnow -F simd`. For some it offers significant performance improvements
//! - When enough cases of an [`alt`] have unique prefixes, prefer [`dispatch`]
//! - When parsing text, try to parse as bytes (`u8`) rather than `char`s ([`BStr`] can make
//!   debugging easier)
//! - Find simplified subsets of the grammar to parse, falling back to the full grammar when it
//!   doesn't work. For example, when parsing json strings, parse them without support for escapes,
//!   falling back to escape support if it fails.
//! - Watch for large return types. A surprising place these can show up is when chaining parsers
//!   with a tuple.
//!
//! ## Build-time Performance
//!
//! Returning complex types as `impl Trait` can negatively impact build times. This can hit in
//! surprising cases like:
//! ```rust
//! # use winnow::prelude::*;
//! fn foo<I, O, E>() -> impl Parser<I, O, E>
//! # where
//! #    I: winnow::stream::Stream<Token=O>,
//! #    I: winnow::stream::StreamIsPartial,
//! #    E: winnow::error::ParserError<I>,
//! {
//!     // ...some chained combinators...
//! # winnow::token::any
//! }
//! ```
//!
//! Instead, wrap the combinators in a closure to simplify the type:
//! ```rust
//! # use winnow::prelude::*;
//! fn foo<I, O, E>() -> impl Parser<I, O, E>
//! # where
//! #    I: winnow::stream::Stream<Token=O>,
//! #    I: winnow::stream::StreamIsPartial,
//! #    E: winnow::error::ParserError<I>,
//! {
//!     move |input: &mut I| {
//!         // ...some chained combinators...
//! # winnow::token::any
//!             .parse_next(input)
//!     }
//! }
//! ```

#![allow(unused_imports)]
use crate::combinator::alt;
use crate::combinator::dispatch;
use crate::stream::BStr;

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/winnow-0.6.24/src/_topic/performance.rs
wasmtime-28.0.0 ./ext/cargo-vendor/winnow-0.6.22/src/_topic/performance.rs
wasmtime-27.0.0 ./ext/cargo-vendor/winnow-0.6.20/src/_topic/performance.rs
wasmtime-26.0.0 ./ext/cargo-vendor/winnow-0.6.20/src/_topic/performance.rs
wasmtime-25.0.2 ./ext/cargo-vendor/winnow-0.6.18/src/_topic/performance.rs
wasmtime-25.0.1 ./ext/cargo-vendor/winnow-0.6.18/src/_topic/performance.rs
wasmtime-25.0.0 ./ext/cargo-vendor/winnow-0.6.18/src/_topic/performance.rs
wasmtime-24.0.0 ./ext/cargo-vendor/winnow-0.6.18/src/_topic/performance.rs
wasmtime-23.0.2 ./ext/cargo-vendor/winnow-0.6.7/src/_topic/performance.rs
wasmtime-22.0.0 ./ext/cargo-vendor/winnow-0.6.7/src/_topic/performance.rs
wasmtime-21.0.1 ./ext/cargo-vendor/winnow-0.6.7/src/_topic/performance.rs
wasmtime-20.0.2 ./ext/cargo-vendor/winnow-0.6.7/src/_topic/performance.rs
wasmtime-20.0.0 ./ext/cargo-vendor/winnow-0.6.7/src/_topic/performance.rs