Skip to content

feat: reduce dependency tree by ~30% for default and minimal builds - #297

Merged
FalkWoldmann merged 2 commits into
masterfrom
reduce-dependencies
Sep 27, 2026
Merged

FalkWoldmann merged 2 commits into
masterfrom
reduce-dependencies

Conversation

@alexliesenfeld

@alexliesenfeld alexliesenfeld commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Closes #46 (revives the old dependency-reduction effort; isahc/async-std from the original report are long gone, this addresses what remained).

Results

Build Before After
--no-default-features 74 crates 52 crates −30%
default features 86 crates 64 crates −26%

Changes

  • Gate hyper-util/server-auto behind the http2 feature. It unconditionally enabled hyper/http2, pulling the h2 subtree (indexmap, hashbrown, equivalent, fnv, slab, tokio-util, atomic-waker) into every build regardless of the http2 feature. Without http2, the server now uses hyper's plain http1::Builder with .with_upgrades() (CONNECT tunneling still works; verified by the https/proxy tests).
  • Replace async-object-pool with a small in-crate pool (src/common/pool.rs, −5 crates): std::sync::Mutex<Vec<T>> + tokio::sync::Semaphore, which is reactor-free and therefore runtime-agnostic — unit tests cover reuse, blocking at capacity, panic-safe creation, and operation under smol without a tokio runtime.
  • Drop futures-util (−5 crates): .shared() → std::pin::pin! + &mut re-polling in select!; pin_mut! → std::pin::pin!; BoxFuture spelled out.
  • Inline three small helpers (−4 crates): tabwriter (+unicode-width), stringmetrics, serde_regex.
  • Move tokio/signal into the standalone feature (−1 crate): only the binary uses signal handling.
  • Fix a latent CryptoProvider install race in src/common/http.rs: check-then-install could panic when two clients were created concurrently. The old pool masked it by serializing creation under its lock.

Verification

  • Differential-tested the Levenshtein replacement against stringmetrics (20,000 randomized cases across both original call sites — exact agreement), and the tab alignment against tabwriter (byte-identical output for all patterns this crate emits, including the minwidth: 2 default).
  • Two review rounds applied: fixed a pool permit leak on creator panic, restored stringmetrics' prefix/suffix trimming (avoids O(n·m) blowup on large bodies), bounded the DP row by the shorter operand, Semaphore::MAX_PERMITS clamp, and assorted cleanups.
  • cargo test passes for default, --no-default-features, and --all-features; cargo check passes for standalone, https, http2, remote, record; clippy and rustfmt clean.

Behavior change

Cleartext HTTP/2 prior-knowledge connections (e.g. gRPC clients) now require the http2 feature — previously they worked in every build only because server-auto force-enabled HTTP/2. Documented in CHANGELOG.md. Known cosmetic limitation: the inlined tab alignment measures chars instead of Unicode display columns; this can only affect failure-report alignment when user data contains both a literal tab and wide characters (noted in a doc comment).

)

Cuts 22 crates from the default build (86 -> 64) and the minimal build
(74 -> 52) without removing functionality:

- Gate hyper-util/server-auto behind the http2 feature. It unconditionally
  enabled hyper/http2, pulling the h2 subtree (indexmap, hashbrown, slab,
  tokio-util, ...) into every build. Without http2, the server now uses
  hyper's plain http1 builder with upgrade support.
- Replace async-object-pool with a small in-crate, runtime-agnostic pool
  based on std Mutex + tokio::sync::Semaphore (reactor-free, works under
  smol/actix-rt; covered by unit tests including a no-tokio-runtime test).
- Drop futures-util: shared() replaced with pin!-based re-polling,
  pin_mut! with std::pin::pin!, BoxFuture spelled out.
- Inline small helpers to drop tabwriter (+unicode-width), stringmetrics,
  and serde_regex. The Levenshtein replacement was differential-tested
  against stringmetrics (20k randomized cases) and trims common
  prefix/suffix; the tab alignment produces byte-identical output for all
  patterns this crate generates.
- Move tokio/signal into the standalone feature (only used by the binary).
- Fix a latent check-then-install race on the rustls CryptoProvider that
  surfaced once pool object creation was no longer serialized.

Behavior change (documented in CHANGELOG): cleartext HTTP/2 prior-knowledge
connections now require the http2 feature.

Closes #46
@alexliesenfeld

Copy link
Copy Markdown
Member Author

Candidate for release 10.x.x .

@httpmock httpmock deleted a comment from codecov Bot Sep 2, 2026
@FalkWoldmann
FalkWoldmann self-requested a review September 20, 2026 15:02
Comment thread Cargo.toml
tracing = { version = "0.1", features = ["log"] }
stringmetrics = "2"
assert-json-diff = "2"
async-trait = "0.1"

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.

Would also be great to get rid of this one but probably not possible due to dyn

Comment thread src/api/output.rs
/// output for the patterns this module generates. It measures cell width in `char`s
/// rather than display columns, so cells containing wide characters (e.g. CJK) may
/// align differently in terminals.
struct TabWriter {

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.

Overall I like getting rid of external deps but I would still argue for tabwriter to stay since it's from a well known and trusted author

# Conflicts:
#	CHANGELOG.md
#	src/server/matchers/comparators.rs
#	src/server/matchers/comparison.rs
@codecov

codecov Bot commented Sep 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.80519% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/common/data.rs 0.00% 7 Missing ⚠️
src/api/output.rs 97.91% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@FalkWoldmann
FalkWoldmann merged commit e0b27fa into master Sep 27, 2026
16 checks passed
FalkWoldmann added a commit to danieleades/httpmock that referenced this pull request Sep 27, 2026
Also fixes what master broke without conflicts: gate the cookie readers now that httpmock#297 made cookies optional, drop the KeyValueOperator variants nothing constructs since httpmock#312 made matchers private, and remove a TryInto import the redundant_imports lint from httpmock#316 rejects.
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.

Add features to reduce dependencies

2 participants