From ef7b1b498cea28935e4c75c1539c16fec927751c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 22 Dec 2019 12:07:13 +0200 Subject: [PATCH] Add combine-based benchmark that caused a large performance regression See https://github.com/rust-lang/rust/issues/67454 --- collector/benchmarks/README.md | 3 ++ collector/benchmarks/combine/.gitignore | 2 + collector/benchmarks/combine/Cargo.lock | 62 +++++++++++++++++++++++++ collector/benchmarks/combine/Cargo.toml | 9 ++++ collector/benchmarks/combine/src/lib.rs | 35 ++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 collector/benchmarks/combine/.gitignore create mode 100644 collector/benchmarks/combine/Cargo.lock create mode 100644 collector/benchmarks/combine/Cargo.toml create mode 100644 collector/benchmarks/combine/src/lib.rs diff --git a/collector/benchmarks/README.md b/collector/benchmarks/README.md index f0962e2a0..2df533ac4 100644 --- a/collector/benchmarks/README.md +++ b/collector/benchmarks/README.md @@ -67,6 +67,9 @@ programs. - **coercions**: Contains a static array with 65,536 string literals, which caused [poor performance](https://github.com/rust-lang/rust/issues/32278) in the past. +- **combine**: Contains a small `combine`-based parser that caused a [large + performance regression](https://github.com/rust-lang/rust/issues/67454) in + the past. - **ctfe-stress-4**: A stress test for compile-time function evaluation. - **deeply-nested**: A small program that caused [exponential behavior](https://github.com/rust-lang/rust/issues/38528) in the past. diff --git a/collector/benchmarks/combine/.gitignore b/collector/benchmarks/combine/.gitignore new file mode 100644 index 000000000..53eaa2196 --- /dev/null +++ b/collector/benchmarks/combine/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/collector/benchmarks/combine/Cargo.lock b/collector/benchmarks/combine/Cargo.lock new file mode 100644 index 000000000..e48644983 --- /dev/null +++ b/collector/benchmarks/combine/Cargo.lock @@ -0,0 +1,62 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "ascii" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "byteorder" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "combine" +version = "3.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ascii 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "combine-bench" +version = "0.1.0" +dependencies = [ + "combine 3.8.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "memchr" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unreachable" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum ascii 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" +"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" +"checksum combine 3.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" +"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" +"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" +"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" diff --git a/collector/benchmarks/combine/Cargo.toml b/collector/benchmarks/combine/Cargo.toml new file mode 100644 index 000000000..f5f336142 --- /dev/null +++ b/collector/benchmarks/combine/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "combine-bench" +license = "MIT" +version = "0.1.0" +authors = ["Sebastian Dröge ", "François Laignel "] +edition = "2018" + +[dependencies] +combine = "3.8" diff --git a/collector/benchmarks/combine/src/lib.rs b/collector/benchmarks/combine/src/lib.rs new file mode 100644 index 000000000..b0ccff271 --- /dev/null +++ b/collector/benchmarks/combine/src/lib.rs @@ -0,0 +1,35 @@ +use combine::byte::hex_digit; +use combine::{choice, token}; +use combine::{ParseError, Parser, RangeStream}; + +pub fn parse<'a, I: 'a>() -> impl Parser +where + I: RangeStream, + I::Error: ParseError, +{ + choice!( + token(b'A').map(|_| 1), + token(b'B').map(|_| 2), + token(b'C').map(|_| 3), + token(b'D').map(|_| 4), + token(b'E').map(|_| 5), + token(b'F').map(|_| 6), + token(b'G').map(|_| 7), + token(b'H').map(|_| 8), + token(b'I').map(|_| 9), + token(b'J').map(|_| 10), + token(b'K').map(|_| 11), + token(b'L').map(|_| 12), + token(b'M').map(|_| 13), + token(b'N').map(|_| 14), + token(b'O').map(|_| 15), + token(b'P').map(|_| 16), + token(b'Q').map(|_| 17), + token(b'R').map(|_| 18), + (hex_digit(), hex_digit()).map(|(u, l)| { + let val = (u << 4) | l; + val + }) + ) + .message("while parsing") +}