mirror of
https://github.com/actix/actix-web.git
synced 2025-02-19 20:36:16 +00:00
perf: remove unnecessary allocation when writing http dates (#3261)
This commit is contained in:
parent
7e4e12b0aa
commit
1e2ef6f92f
29 changed files with 75 additions and 61 deletions
14
.github/workflows/ci.yml
vendored
14
.github/workflows/ci.yml
vendored
|
@ -26,7 +26,7 @@ jobs:
|
||||||
- { name: macOS, os: macos-latest, triple: x86_64-apple-darwin }
|
- { name: macOS, os: macos-latest, triple: x86_64-apple-darwin }
|
||||||
- { name: Windows, os: windows-latest, triple: x86_64-pc-windows-msvc }
|
- { name: Windows, os: windows-latest, triple: x86_64-pc-windows-msvc }
|
||||||
version:
|
version:
|
||||||
- { name: msrv, version: 1.68.0 }
|
- { name: msrv, version: 1.70.0 }
|
||||||
- { name: stable, version: stable }
|
- { name: stable, version: stable }
|
||||||
|
|
||||||
name: ${{ matrix.target.name }} / ${{ matrix.version.name }}
|
name: ${{ matrix.target.name }} / ${{ matrix.version.name }}
|
||||||
|
@ -54,14 +54,10 @@ jobs:
|
||||||
with:
|
with:
|
||||||
tool: cargo-hack,cargo-ci-cache-clean
|
tool: cargo-hack,cargo-ci-cache-clean
|
||||||
|
|
||||||
- name: workaround MSRV issues
|
# - name: workaround MSRV issues
|
||||||
if: matrix.version.name == 'msrv'
|
# if: matrix.version.name == 'msrv'
|
||||||
run: |
|
# run: |
|
||||||
cargo update -p=ciborium --precise=0.2.1
|
# cargo update -p=anstyle --precise=1.0.2
|
||||||
cargo update -p=ciborium-ll --precise=0.2.1
|
|
||||||
cargo update -p=clap --precise=4.3.24
|
|
||||||
cargo update -p=clap_lex --precise=0.5.0
|
|
||||||
cargo update -p=anstyle --precise=1.0.2
|
|
||||||
|
|
||||||
- name: check minimal
|
- name: check minimal
|
||||||
run: cargo ci-check-min
|
run: cargo ci-check-min
|
||||||
|
|
|
@ -17,7 +17,7 @@ members = [
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.68"
|
rust-version = "1.70"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
# Disabling debug info speeds up builds a bunch and we don't rely on it for debugging that much.
|
# Disabling debug info speeds up builds a bunch and we don't rely on it for debugging that much.
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.70.
|
||||||
|
|
||||||
## 0.6.5
|
## 0.6.5
|
||||||
|
|
||||||
- Fix handling of special characters in filenames.
|
- Fix handling of special characters in filenames.
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-files)
|
[](https://crates.io/crates/actix-files)
|
||||||
[](https://docs.rs/actix-files/0.6.5)
|
[](https://docs.rs/actix-files/0.6.5)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-files/0.6.5)
|
[](https://deps.rs/crate/actix-files/0.6.5)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.70.
|
||||||
|
|
||||||
## 3.2.0
|
## 3.2.0
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-http-test)
|
[](https://crates.io/crates/actix-http-test)
|
||||||
[](https://docs.rs/actix-http-test/3.2.0)
|
[](https://docs.rs/actix-http-test/3.2.0)
|
||||||

|

|
||||||

|

|
||||||
<br>
|
<br>
|
||||||
[](https://deps.rs/crate/actix-http-test/3.2.0)
|
[](https://deps.rs/crate/actix-http-test/3.2.0)
|
||||||
|
@ -14,8 +14,3 @@
|
||||||
[](https://discord.gg/NWpN5mmg3x)
|
[](https://discord.gg/NWpN5mmg3x)
|
||||||
|
|
||||||
<!-- prettier-ignore-end -->
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
## Documentation & Resources
|
|
||||||
|
|
||||||
- [API Documentation](https://docs.rs/actix-http-test)
|
|
||||||
- Minimum Supported Rust Version (MSRV): 1.68
|
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.70.
|
||||||
|
|
||||||
## 3.6.0
|
## 3.6.0
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -126,6 +126,7 @@ actix-web = "4"
|
||||||
|
|
||||||
async-stream = "0.3"
|
async-stream = "0.3"
|
||||||
criterion = { version = "0.5", features = ["html_reports"] }
|
criterion = { version = "0.5", features = ["html_reports"] }
|
||||||
|
divan = "0.1.8"
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
futures-util = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
futures-util = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||||
memchr = "2.4"
|
memchr = "2.4"
|
||||||
|
@ -153,3 +154,7 @@ required-features = ["http2", "rustls-0_22"]
|
||||||
name = "response-body-compression"
|
name = "response-body-compression"
|
||||||
harness = false
|
harness = false
|
||||||
required-features = ["compress-brotli", "compress-gzip", "compress-zstd"]
|
required-features = ["compress-brotli", "compress-gzip", "compress-zstd"]
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "date-formatting"
|
||||||
|
harness = false
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-http)
|
[](https://crates.io/crates/actix-http)
|
||||||
[](https://docs.rs/actix-http/3.6.0)
|
[](https://docs.rs/actix-http/3.6.0)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-http/3.6.0)
|
[](https://deps.rs/crate/actix-http/3.6.0)
|
||||||
|
@ -15,11 +15,6 @@
|
||||||
|
|
||||||
<!-- prettier-ignore-end -->
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
## Documentation & Resources
|
|
||||||
|
|
||||||
- [API Documentation](https://docs.rs/actix-http)
|
|
||||||
- Minimum Supported Rust Version (MSRV): 1.68
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
|
20
actix-http/benches/date-formatting.rs
Normal file
20
actix-http/benches/date-formatting.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use std::time::SystemTime;
|
||||||
|
|
||||||
|
use actix_http::header::HttpDate;
|
||||||
|
use divan::{black_box, AllocProfiler, Bencher};
|
||||||
|
|
||||||
|
#[global_allocator]
|
||||||
|
static ALLOC: AllocProfiler = AllocProfiler::system();
|
||||||
|
|
||||||
|
#[divan::bench]
|
||||||
|
fn date_formatting(b: Bencher<'_, '_>) {
|
||||||
|
let now = SystemTime::now();
|
||||||
|
|
||||||
|
b.bench(|| {
|
||||||
|
black_box(HttpDate::from(black_box(now)).to_string());
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
divan::main();
|
||||||
|
}
|
|
@ -28,7 +28,7 @@ impl Date {
|
||||||
|
|
||||||
fn update(&mut self) {
|
fn update(&mut self) {
|
||||||
self.pos = 0;
|
self.pos = 0;
|
||||||
write!(self, "{}", httpdate::fmt_http_date(SystemTime::now())).unwrap();
|
write!(self, "{}", httpdate::HttpDate::from(SystemTime::now())).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,7 @@ impl FromStr for HttpDate {
|
||||||
|
|
||||||
impl fmt::Display for HttpDate {
|
impl fmt::Display for HttpDate {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let date_str = httpdate::fmt_http_date(self.0);
|
httpdate::HttpDate::from(self.0).fmt(f)
|
||||||
f.write_str(&date_str)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +36,7 @@ impl TryIntoHeaderValue for HttpDate {
|
||||||
let mut wrt = MutWriter(&mut buf);
|
let mut wrt = MutWriter(&mut buf);
|
||||||
|
|
||||||
// unwrap: date output is known to be well formed and of known length
|
// unwrap: date output is known to be well formed and of known length
|
||||||
write!(wrt, "{}", httpdate::fmt_http_date(self.0)).unwrap();
|
write!(wrt, "{}", self).unwrap();
|
||||||
|
|
||||||
HeaderValue::from_maybe_shared(buf.split().freeze())
|
HeaderValue::from_maybe_shared(buf.split().freeze())
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.70.
|
||||||
|
|
||||||
## 0.6.1
|
## 0.6.1
|
||||||
|
|
||||||
- Update `syn` dependency to `2`.
|
- Update `syn` dependency to `2`.
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-multipart-derive)
|
[](https://crates.io/crates/actix-multipart-derive)
|
||||||
[](https://docs.rs/actix-multipart-derive/0.6.1)
|
[](https://docs.rs/actix-multipart-derive/0.6.1)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-multipart-derive/0.6.1)
|
[](https://deps.rs/crate/actix-multipart-derive/0.6.1)
|
||||||
|
@ -14,8 +14,3 @@
|
||||||
[](https://discord.gg/NWpN5mmg3x)
|
[](https://discord.gg/NWpN5mmg3x)
|
||||||
|
|
||||||
<!-- prettier-ignore-end -->
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
## Documentation & Resources
|
|
||||||
|
|
||||||
- [API Documentation](https://docs.rs/actix-multipart-derive)
|
|
||||||
- Minimum Supported Rust Version (MSRV): 1.68
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[rustversion::stable(1.68)] // MSRV
|
#[rustversion::stable(1.70)] // MSRV
|
||||||
#[test]
|
#[test]
|
||||||
fn compile_macros() {
|
fn compile_macros() {
|
||||||
let t = trybuild::TestCases::new();
|
let t = trybuild::TestCases::new();
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.70.
|
||||||
|
|
||||||
## 0.6.1
|
## 0.6.1
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-multipart)
|
[](https://crates.io/crates/actix-multipart)
|
||||||
[](https://docs.rs/actix-multipart/0.6.1)
|
[](https://docs.rs/actix-multipart/0.6.1)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-multipart/0.6.1)
|
[](https://deps.rs/crate/actix-multipart/0.6.1)
|
||||||
|
@ -14,8 +14,3 @@
|
||||||
[](https://discord.gg/NWpN5mmg3x)
|
[](https://discord.gg/NWpN5mmg3x)
|
||||||
|
|
||||||
<!-- prettier-ignore-end -->
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
## Documentation & Resources
|
|
||||||
|
|
||||||
- [API Documentation](https://docs.rs/actix-multipart)
|
|
||||||
- Minimum Supported Rust Version (MSRV): 1.68
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.70.
|
||||||
|
|
||||||
## 0.5.2
|
## 0.5.2
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-router)
|
[](https://crates.io/crates/actix-router)
|
||||||
[](https://docs.rs/actix-router/0.5.2)
|
[](https://docs.rs/actix-router/0.5.2)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-router/0.5.2)
|
[](https://deps.rs/crate/actix-router/0.5.2)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.70.
|
||||||
|
|
||||||
## 0.1.3
|
## 0.1.3
|
||||||
|
|
||||||
- Add `TestServerConfig::rustls_0_22()` method for Rustls v0.22 support behind new `rustls-0_22` crate feature.
|
- Add `TestServerConfig::rustls_0_22()` method for Rustls v0.22 support behind new `rustls-0_22` crate feature.
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.70.
|
||||||
|
|
||||||
## 4.3.0
|
## 4.3.0
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-web-actors)
|
[](https://crates.io/crates/actix-web-actors)
|
||||||
[](https://docs.rs/actix-web-actors/4.3.0)
|
[](https://docs.rs/actix-web-actors/4.3.0)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-web-actors/4.3.0)
|
[](https://deps.rs/crate/actix-web-actors/4.3.0)
|
||||||
|
@ -14,8 +14,3 @@
|
||||||
[](https://discord.gg/NWpN5mmg3x)
|
[](https://discord.gg/NWpN5mmg3x)
|
||||||
|
|
||||||
<!-- prettier-ignore-end -->
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
## Documentation & Resources
|
|
||||||
|
|
||||||
- [API Documentation](https://docs.rs/actix-web-actors)
|
|
||||||
- Minimum Supported Rust Version (MSRV): 1.68
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.70.
|
||||||
|
|
||||||
## 4.2.2
|
## 4.2.2
|
||||||
|
|
||||||
- Fix regression when declaring `wrap` attribute using an expression.
|
- Fix regression when declaring `wrap` attribute using an expression.
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-web-codegen)
|
[](https://crates.io/crates/actix-web-codegen)
|
||||||
[](https://docs.rs/actix-web-codegen/4.2.2)
|
[](https://docs.rs/actix-web-codegen/4.2.2)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-web-codegen/4.2.2)
|
[](https://deps.rs/crate/actix-web-codegen/4.2.2)
|
||||||
|
@ -15,11 +15,6 @@
|
||||||
|
|
||||||
<!-- prettier-ignore-end -->
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
## Documentation & Resources
|
|
||||||
|
|
||||||
- [API Documentation](https://docs.rs/actix-web-codegen)
|
|
||||||
- Minimum Supported Rust Version (MSRV): 1.68
|
|
||||||
|
|
||||||
## Compile Testing
|
## Compile Testing
|
||||||
|
|
||||||
Uses the [`trybuild`] crate. All compile fail tests should include a stderr file generated by `trybuild`. See the [workflow section](https://github.com/dtolnay/trybuild#workflow) of the trybuild docs for info on how to do this.
|
Uses the [`trybuild`] crate. All compile fail tests should include a stderr file generated by `trybuild`. See the [workflow section](https://github.com/dtolnay/trybuild#workflow) of the trybuild docs for info on how to do this.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[rustversion::stable(1.68)] // MSRV
|
#[rustversion::stable(1.70)] // MSRV
|
||||||
#[test]
|
#[test]
|
||||||
fn compile_macros() {
|
fn compile_macros() {
|
||||||
let t = trybuild::TestCases::new();
|
let t = trybuild::TestCases::new();
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.70.
|
||||||
|
|
||||||
## 4.5.1
|
## 4.5.1
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-web)
|
[](https://crates.io/crates/actix-web)
|
||||||
[](https://docs.rs/actix-web/4.5.1)
|
[](https://docs.rs/actix-web/4.5.1)
|
||||||

|

|
||||||

|

|
||||||
[](https://deps.rs/crate/actix-web/4.5.1)
|
[](https://deps.rs/crate/actix-web/4.5.1)
|
||||||
<br />
|
<br />
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
- SSL support using OpenSSL or Rustls
|
- SSL support using OpenSSL or Rustls
|
||||||
- Middlewares ([Logger, Session, CORS, etc](https://actix.rs/docs/middleware/))
|
- Middlewares ([Logger, Session, CORS, etc](https://actix.rs/docs/middleware/))
|
||||||
- Integrates with the [`awc` HTTP client](https://docs.rs/awc/)
|
- Integrates with the [`awc` HTTP client](https://docs.rs/awc/)
|
||||||
- Runs on stable Rust 1.68+
|
- Runs on stable Rust 1.70+
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.70.
|
||||||
|
|
||||||
## 3.4.0
|
## 3.4.0
|
||||||
|
|
||||||
- Add `rustls-0_22-webpki-roots` and `rustls-0_22-native-roots` crate feature.
|
- Add `rustls-0_22-webpki-roots` and `rustls-0_22-native-roots` crate feature.
|
||||||
|
|
|
@ -12,13 +12,11 @@
|
||||||
|
|
||||||
<!-- prettier-ignore-end -->
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
## Documentation & Resources
|
## Examples
|
||||||
|
|
||||||
- [API Documentation](https://docs.rs/awc)
|
[Example project using TLS-enabled client →](https://github.com/actix/examples/tree/master/https-tls/awc-https)
|
||||||
- [Example Project](https://github.com/actix/examples/tree/master/https-tls/awc-https)
|
|
||||||
- Minimum Supported Rust Version (MSRV): 1.68
|
|
||||||
|
|
||||||
## Example
|
Basic usage:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use actix_rt::System;
|
use actix_rt::System;
|
||||||
|
|
Loading…
Reference in a new issue