Skip to content

ci: add paired Python SDK performance benchmarks - #1134

Open
dustinbyrne wants to merge 2 commits into
mainfrom
feat/python-performance-benchmarks
Open

dustinbyrne wants to merge 2 commits into
mainfrom
feat/python-performance-benchmarks

Conversation

@dustinbyrne

Copy link
Copy Markdown
Contributor

Motivation and context

Add reproducible PR-local measurements of Python SDK flag evaluation, allocation churn, memory under load/refresh, and capture/drain. This is the Python producer for the same provisional JSON contract as Node.

Changes

  • Add 18 deterministic public-entry workloads and isolated alternating base/head workers.
  • Build independently installed wheels with locked dependencies, forced fresh builds, and matched precompiled bytecode.
  • Measure elapsed/process CPU, Python allocator bytes/calls including freed allocations, and checkpoint/lifetime RSS in separate passes.
  • Keep foreground enqueue thread CPU distinct from complete delivery measurements; the loopback receiver runs outside the worker. Drain completion stays inside measurement.
  • Add a read-only PR workflow with JSON artifacts and summary links. Performance is informational; correctness/execution failures remain failures.

Shared report rendering and commenting will integrate in a stacked follow-up. No SDK runtime changes or release required.

How did you test it?

  • 16 controls passed, including deliberate CPU/allocation/retained-refresh regressions, delayed draining, payload/identity checks, installed-build provenance, and error/timeout/RSS-limit classification.
  • 285 existing feature-flag tests and 415 subtests passed.
  • Complete same-commit run: 18 workloads, six paired repetitions, 408 successful workers in 290.69 seconds (CPython 3.12.12, macOS ARM64; excludes install/build).
  • Ruff, benchmark Mypy, Actionlint, and diff checks passed. Linux CI calibration remains outstanding.
  • Fresh read-only review findings were reproduced and fixed, including stale local wheel reuse and draining outside measurement.

Checklist

  • All commits signed
  • Tests and documentation added
  • No SDK runtime or backwards-compatibility changes

Agent context

Autonomy: Human-driven (agent-assisted).
Implemented with Pi and a fresh read-only reviewer. Allocator calls are explicitly not object counts; unsupported uninstrumented heap bytes and enqueue-only allocations remain visible rather than represented as zero.

@dustinbyrne dustinbyrne added the stamphog Request stamphog review label Oct 27, 2026
@dustinbyrne
dustinbyrne requested a review from a team as a code owner October 27, 2026 21:40
@dustinbyrne dustinbyrne self-assigned this Oct 27, 2026

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not approved yet — waiting on the conditions below.

Re-add the stamphog label to request another review once you have addressed this.

stamphog declined to auto-review this pull request because three gates failed. The deny-list gate matched dependency/toolchain files (benchmarks/requirements.in and benchmarks/requirements.txt) and CI/CD infrastructure (.github/workflows/benchmarks.yml). The size gate failed because the change has 1289 substantive lines against an 800-line ceiling. The tier gate classified it as T2-never because it spans two areas and touches CI.

Please ask a human reviewer to look at it. If you want it to be reviewable on its own, consider splitting it so the workflow and dependency lockfile changes land separately from the benchmark code, with each part under the size ceiling.

Gate mechanics and policy version
Gate Result
prerequisites ✓ all clear
deny-list ✗ matches: deps_toolchain, infra_cicd
size ✗ too large for auto-review (1289L substantive in global — ceiling is 800L; 1289L, 11F total, 2043L/14F incl. docs/generated/snapshots)
tier ✗ classified as T2-never: T2-never (2043L, 14F, two-areas, ci)
stamphog 2.6.1 .stamphog/policy.yml @ unknown · reviewed head 50dff4b

@stamphog stamphog Bot removed the stamphog Request stamphog review label Oct 27, 2026

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 50dff4b: 2 Should fix. This pull request is large, so the review ran in 4 parts with less depth than usual.

See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.

Comment thread benchmarks/run.py Outdated
with subprocess.Popen(
command,
cwd=directory,
env=worker_env(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 · Keep profiler traces inside the coordinator-owned temporary directory

When an allocation worker exceeds its timeout or RSS limit, process.kill() bypasses cleanup of sample_allocations()'s temporary directory. run_worker() removes only its separate result directory, leaving large Memray traces behind. Repeated failures accumulate disk usage on local and self-hosted runners; set the child's TMPDIR to the coordinator-owned directory.

Comment thread benchmarks/run.py
Comment on lines +383 to +384
if any(record["status"] != "ok" for record in records.values()):
break

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 · Bound cumulative time spent on failed workers

When a flag-evaluation regression hangs each head worker, this break skips only remaining repetitions and continues through every workload and pass. The nine single-flag workloads alone consume 36 minutes of head-worker timeouts, exceeding the workflow's 30-minute budget before later workloads run; enforce a suite deadline or stop after repeated timeouts.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

posthog-python Compliance Report

Date: 2026-10-27T21:56:30.406425+00:00
Duration: 259943ms

✅ All Tests Passed!

121/121 tests passed


Capture_V1 Tests

✅ 95/95 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 516ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 511ms
Required Headers.Has Authorization Bearer Header ✅ 511ms
Required Headers.Has Content Type Json ✅ 510ms
Required Headers.Has Posthog Sdk Info Format ✅ 510ms
Required Headers.Has Posthog Attempt Header ✅ 510ms
Required Headers.Has Posthog Request Id ✅ 510ms
Required Headers.Has Posthog Request Timestamp ✅ 511ms
Required Headers.Has User Agent ✅ 510ms
Body Format.Body Has Created At And Batch ✅ 510ms
Body Format.No Api Key In Body ✅ 511ms
Body Format.No Sent At In Body ✅ 510ms
Event Format.Event Has Required Root Fields ✅ 510ms
Event Format.Event Uuid Is Valid ✅ 510ms
Event Format.Event Timestamp Is Rfc3339 ✅ 511ms
Event Format.Non Utc Event Timestamp Is Converted To Utc ✅ 523ms
Event Format.Distinct Id Is String ✅ 511ms
Event Format.Distinct Id At Root Not Properties ✅ 510ms
Event Format.Custom Properties Preserved ✅ 510ms
Event Format.Set Properties Preserved ✅ 510ms
Event Format.Set Once Properties Preserved ✅ 511ms
Event Format.Groups Properties Preserved ✅ 510ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 510ms
Event Format.Event Has Required Root Fields Batch ✅ 514ms
Event Format.Event Uuid Is Valid Batch ✅ 514ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 514ms
Event Format.Distinct Id Is String Batch ✅ 514ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 514ms
Event Format.Custom Properties Preserved Batch ✅ 513ms
Event Format.Set Properties Preserved Batch ✅ 513ms
Event Format.Set Once Properties Preserved Batch ✅ 514ms
Event Format.Groups Properties Preserved Batch ✅ 514ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 514ms
Batch Behavior.Multiple Events In Single Batch ✅ 518ms
Batch Behavior.Batch Envelope Smoke ✅ 516ms
Batch Behavior.Flush With No Events Sends Nothing ✅ 507ms
Batch Behavior.Flush At Triggers Batch ✅ 1011ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 511ms
Deduplication.Generates Unique Uuids ✅ 518ms
Deduplication.Different Events Same Content Different Uuids ✅ 513ms
Deduplication.Preserves Uuid On Retry ✅ 6518ms
Deduplication.Preserves Timestamp On Retry ✅ 6521ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 6523ms
Deduplication.No Duplicate Events In Batch ✅ 518ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 511ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 13528ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 6519ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 3020ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 6520ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 511ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 516ms
Response Format Validation.Success No Retry After When All Ok ✅ 513ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 1516ms
Response Format Validation.Success No Retry After When Drop Only ✅ 513ms
Response Format Validation.Response Echoes Request Id ✅ 510ms
Retry Behavior.Retries On 408 ✅ 6520ms
Retry Behavior.Retries On 500 ✅ 6520ms
Retry Behavior.Retries On 503 ✅ 8523ms
Retry Behavior.Retries On 504 ✅ 6517ms
Retry Behavior.Retryable Errors Have Retry After ✅ 3519ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 11517ms
Retry Behavior.Does Not Retry On 400 ✅ 2514ms
Retry Behavior.Does Not Retry On 401 ✅ 2513ms
Retry Behavior.Does Not Retry On 402 ✅ 2513ms
Retry Behavior.Does Not Retry On 413 ✅ 2512ms
Retry Behavior.Does Not Retry On 415 ✅ 2513ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 2513ms
Retry Behavior.Implements Backoff ✅ 22525ms
Retry Behavior.Max Retries Respected ✅ 22537ms
Partial Batch Handling.Handles 200 Full Success ✅ 2513ms
Partial Batch Handling.Handles 200 With All Ok ✅ 3518ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 3516ms
Partial Batch Handling.Does Not Retry Limited Events ✅ 3516ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 6522ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 6521ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 6524ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 6523ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 6522ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 6523ms
Partial Batch Handling.Respects Retry After On Partial ✅ 8521ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 3517ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry ✅ 3521ms
Compression.Sends Gzip Content Encoding ✅ 512ms
Compression.No Content Encoding When Disabled ✅ 510ms
Compression.Compressed Body Is Decompressible ✅ 511ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 2512ms
Event Options.Cookieless Mode Override ✅ 510ms
Event Options.Disable Skew Correction Override ✅ 511ms
Event Options.Process Person Profile Override ✅ 510ms
Event Options.Product Tour Id Override ✅ 511ms
Event Options.Unset Options Omitted ✅ 511ms
Event Options.Options Override In Batch ✅ 514ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties ✅ 511ms
Geoip And Historical Migration.Historical Migration Set In Body ✅ 512ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 510ms

Capture_Ai Tests

✅ 5/5 tests passed

View Details
Test Status Duration
Routing.Capture Ai Posts To Ai Endpoint ✅ 511ms
Routing.Capture Does Not Reroute Ai Named Events ✅ 511ms
Identity.Capture Ai Event Has Uuid ✅ 511ms
Identity.Capture Ai Keeps Supplied Uuid ✅ 511ms
Timestamp Format.Non Utc Event Timestamp Is Converted To Utc ✅ 512ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 12ms
Request Payload.Flags Request Uses V2 Query Param ✅ 11ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 10ms
Request Payload.Flags Request Omits Authorization Header ✅ 11ms
Request Payload.Token In Flags Body Matches Init ✅ 10ms
Request Payload.Groups Round Trip ✅ 10ms
Request Payload.Groups Default To Empty Object ✅ 11ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 10ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 11ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 12ms
Request Lifecycle.No Flags Request On Init Alone ✅ 4ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 511ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 15ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 9ms
Retry Behavior.Retries Flags On 502 ✅ 314ms
Retry Behavior.Retries Flags On 504 ✅ 313ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 512ms

Feature_Flags_Local_Evaluation Tests

✅ 4/4 tests passed

View Details
Test Status Duration
Versioned Boolean Matching.Matching Version Missing ✅ 71ms
Versioned Boolean Matching.Matching Version 1 ✅ 68ms
Versioned Boolean Matching.Matching Version 2 ✅ 69ms
Versioned Boolean Matching.Version Only Reload 1 2 1 2 Missing ✅ 36ms

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 89d14a8: no findings. This pull request is large, so the review ran in 4 parts with less depth than usual.

@marandaneto marandaneto left a comment

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.

The code looks good; no qualifying findings. Verdict: correct.

This branch has not been deployed

No deployments
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.

2 participants