From cd2573e0caf468061433abfab8566f870be3a349 Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Sun, 28 Apr 2024 13:27:14 +0200 Subject: [PATCH] :zap: Fix a minor performance regression when building headers frame --- CHANGELOG.rst | 6 ++++++ Cargo.lock | 2 +- Cargo.toml | 4 ++-- jh2/__init__.py | 2 +- jh2/stream.py | 24 ++++++++++-------------- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a37f1d7ca..54e578175 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ Release History =============== +5.0.1 (2024-04-28) +------------------ + +- Fixed a minor performance regression in ``_build_headers_frames`` method. +- (Rust) Bump pyo3 to version 0.20.3 + 5.0.0 (2024-04-28) ------------------ diff --git a/Cargo.lock b/Cargo.lock index e93f490ca..f28dc978d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,7 +49,7 @@ checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" [[package]] name = "jh2" -version = "5.0.0" +version = "5.0.1" dependencies = [ "httlib-hpack", "pyo3", diff --git a/Cargo.toml b/Cargo.toml index a132078c6..c3cb88660 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jh2" -version = "5.0.0" +version = "5.0.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -9,7 +9,7 @@ name = "jh2" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.20.2", features = ["abi3-py37"] } +pyo3 = { version = "0.20.3", features = ["abi3-py37"] } httlib-hpack = { version = "0.1.3" } [package.metadata.maturin] diff --git a/jh2/__init__.py b/jh2/__init__.py index aa3917cf1..5693cb555 100644 --- a/jh2/__init__.py +++ b/jh2/__init__.py @@ -7,4 +7,4 @@ from __future__ import annotations -__version__ = "5.0.0" +__version__ = "5.0.1" diff --git a/jh2/stream.py b/jh2/stream.py index 7133d2045..141f8e3db 100644 --- a/jh2/stream.py +++ b/jh2/stream.py @@ -1351,20 +1351,16 @@ def _build_headers_frames( headers = validate_outbound_headers(headers, hdr_validation_flags) if ALTERNATIVE_HPACK: - buf = [] - - for header in headers: - h, v = header - - if isinstance(h, str): - h = h.encode() - if isinstance(v, str): - v = v.encode() - is_sensitive = isinstance(header, NeverIndexedHeaderTuple) - - buf.append((h, v, is_sensitive)) - - encoded_headers = encoder.encode(buf) + encoded_headers = encoder.encode( + [ + ( + h[0] if isinstance(h[0], bytes) else h[0].encode(), + h[1] if isinstance(h[1], bytes) else h[1].encode(), + isinstance(h, NeverIndexedHeaderTuple), + ) + for h in headers + ] + ) else: encoded_headers = encoder.encode(headers)