Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,27 @@ jobs:
with:
mode: instrumentation
run: uv run pytest tests/test_benchmark.py --codspeed

memory-benchmarks:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Attribute the commit solely to the engineer

This commit records Codex <codex@openai.com> as both author and committer, so the coding agent owns the authorship instead of the engineer. Recreate the commit with the engineer as the sole author before merging, as required by the repository instructions.

AGENTS.md reference: AGENTS.md:L3-L3

Useful? React with 👍 / 👎.

name: Run memory benchmarks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Install uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
python-version: "3.13"
enable-cache: true

- name: Install dependencies
run: scripts/install
shell: bash

- name: Run the benchmarks
uses: CodSpeedHQ/action@f99becdce5e5d51fd556489ebef684f4ecfd6286 # v4.18.5
with:
mode: memory
run: uv run pytest tests/test_benchmark_memory.py --codspeed
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ filterwarnings = [
markers = [
"copied_from(source, changes=None): mark test as copied from somewhere else, along with a description of changes made to accommodate e.g. our test setup",
"network: marks tests which require network connection. Used in 3rd-party build environments that have network disabled.",
"benchmark: marks CodSpeed benchmark tests under tests/test_benchmark.py.",
"benchmark: marks CodSpeed benchmark tests under tests/test_benchmark*.py.",
]

[tool.coverage.run]
source_pkgs = ["httpx2", "httpcore2", "tests"]
omit = ["src/httpcore2/httpcore2/_sync/*", "tests/test_benchmark.py"]
omit = ["src/httpcore2/httpcore2/_sync/*", "tests/test_benchmark*.py"]

[tool.coverage.report]
exclude_also = [
Expand Down
44 changes: 44 additions & 0 deletions tests/test_benchmark_memory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import hpack
import hyperframe.frame
import pytest

import httpcore2

if TYPE_CHECKING:
from pytest_codspeed import BenchmarkFixture

pytestmark = pytest.mark.benchmark

H2_WINDOW = 2**31 - 1
H2_BODY = b"x" * (8 * 1024 * 1024)


def _h2_server_frames() -> list[bytes]:
return [
hyperframe.frame.SettingsFrame(
settings={hyperframe.frame.SettingsFrame.INITIAL_WINDOW_SIZE: H2_WINDOW}
).serialize(),
hyperframe.frame.WindowUpdateFrame(stream_id=0, window_increment=H2_WINDOW - 65535).serialize(),
hyperframe.frame.HeadersFrame(
stream_id=1,
data=hpack.Encoder().encode([(b":status", b"200")]),
flags=["END_HEADERS"],
).serialize(),
hyperframe.frame.DataFrame(stream_id=1, data=b"", flags=["END_STREAM"]).serialize(),
]


def test_bench_http2_send_large_body(benchmark: BenchmarkFixture) -> None:
origin = httpcore2.Origin(b"https", b"example.com", 443)

def send() -> int:
stream = httpcore2.MockStream(_h2_server_frames())
with httpcore2.HTTP2Connection(origin=origin, stream=stream) as conn:
response = conn.request("POST", "https://example.com/", content=H2_BODY)
return response.status

assert benchmark(send) == 200
Loading