Skip to content

test: Set up flattening benchmarks#3686

Merged
edgarrmondragon merged 1 commit into
mainfrom
test/flattenning-benchamarks
Jun 30, 2026
Merged

test: Set up flattening benchmarks#3686
edgarrmondragon merged 1 commit into
mainfrom
test/flattenning-benchamarks

Conversation

@edgarrmondragon

@edgarrmondragon edgarrmondragon commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

SSIA

Summary by Sourcery

Tests:

  • Introduce pytest benchmark suite for flatten_key, flatten_record, and flatten_schema under varying record and schema shapes.

@edgarrmondragon edgarrmondragon self-assigned this Jun 29, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds pytest-based benchmark tests that exercise singer_sdk.helpers._flattening functions (flatten_key, flatten_record, flatten_schema) across short/long key inputs and wide/deep record and schema structures to measure performance characteristics under different shapes and depths of data.

File-Level Changes

Change Details Files
Introduce pytest benchmark suite for flatten_key, flatten_record, and flatten_schema under varied key, record, and schema shapes.
  • Add fixtures to generate short and long key inputs for flatten_key benchmarks.
  • Add fixtures to generate wide flat records/schemas and deeply nested records/schemas for flatten_record and flatten_schema benchmarks.
  • Implement benchmark tests for flatten_key with short and long keys using the pytest benchmark fixture.
  • Implement benchmark tests for flatten_record using pre-flattened schemas for wide and deeply nested data structures.
  • Implement benchmark tests for flatten_schema over wide and deeply nested schemas with controlled max_level parameters.
tests/benchmarks/test_flattening.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.21%. Comparing base (1053b7b) to head (be9c26d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3686   +/-   ##
=======================================
  Coverage   94.21%   94.21%           
=======================================
  Files          73       73           
  Lines        6208     6208           
  Branches      763      763           
=======================================
  Hits         5849     5849           
  Misses        267      267           
  Partials       92       92           
Flag Coverage Δ
core 83.05% <ø> (ø)
end-to-end 76.03% <ø> (ø)
optional-components 44.86% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq

codspeed-hq Bot commented Jun 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 8 untouched benchmarks
🆕 6 new benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_bench_flatten_key_long N/A 136.1 µs N/A
🆕 test_bench_flatten_key_short N/A 35.5 µs N/A
🆕 test_bench_flatten_record_deep N/A 3.2 ms N/A
🆕 test_bench_flatten_record_wide N/A 357.9 µs N/A
🆕 test_bench_flatten_schema_deep N/A 4.5 ms N/A
🆕 test_bench_flatten_schema_wide N/A 1 ms N/A

Comparing test/flattenning-benchamarks (be9c26d) with main (1053b7b)

Open in CodSpeed

@edgarrmondragon edgarrmondragon force-pushed the test/flattenning-benchamarks branch 2 times, most recently from 8fc9667 to 3a161eb Compare June 29, 2026 15:47
@edgarrmondragon edgarrmondragon force-pushed the test/flattenning-benchamarks branch from 3a161eb to 6036d9e Compare June 29, 2026 17:26
@edgarrmondragon

Copy link
Copy Markdown
Collaborator Author

@sourcery-ai review

@sourcery-ai sourcery-ai 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/benchmarks/test_flattening.py" line_range="15" />
<code_context>
+    flatten_schema,
+)
+
+NUMBER_OF_RUNS = 250
+
+
</code_context>
<issue_to_address>
**suggestion (testing):** Manual inner loop over `NUMBER_OF_RUNS` may fight against pytest-benchmark’s own timing controls

Wrapping each benchmarked call in a `run()` that loops `NUMBER_OF_RUNS` times duplicates pytest-benchmark’s own iteration control and can distort or obscure the timing results. Instead, pass the operation directly to `benchmark` (e.g. `benchmark(flatten_key, key, parents)` or `benchmark.pedantic(...)`) and, if needed, adjust the number of rounds via the fixture configuration rather than a custom loop.

Suggested implementation:

```python
from singer_sdk.helpers._flattening import (
    flatten_key,
    flatten_record,
    flatten_schema,
)

from __future__ import annotations

import itertools

import pytest

from singer_sdk.helpers._flattening import (
    flatten_key,
    flatten_record,
    flatten_schema,

```

```python

```

```python
def test_flatten_key_benchmark(benchmark, key, parents):
    benchmark(flatten_key, key, parents)

```

```python
def test_flatten_record_benchmark(benchmark, record, schema):
    benchmark(flatten_record, record, schema)

```

```python
def test_flatten_schema_benchmark(benchmark, schema):
    benchmark(flatten_schema, schema)

```

If you want multiple rounds or warmup behavior, configure this via pytest-benchmark instead of a manual loop, e.g.:
- In `pytest.ini` or `pyproject.toml`, set options such as `benchmark_min_rounds`, `benchmark_max_time`, `benchmark_warmup` as needed.
- Alternatively, if you need more control per-test, you can use `benchmark.pedantic(flatten_key, args=(key, parents), iterations=1, rounds=250)` instead of the simple `benchmark(...)` call, which still avoids a custom inner loop while keeping iteration control with pytest-benchmark.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/benchmarks/test_flattening.py Outdated
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@edgarrmondragon edgarrmondragon force-pushed the test/flattenning-benchamarks branch from 6036d9e to be9c26d Compare June 29, 2026 18:31
@edgarrmondragon edgarrmondragon marked this pull request as ready for review June 30, 2026 01:41
@edgarrmondragon edgarrmondragon added this pull request to the merge queue Jun 30, 2026

@sourcery-ai sourcery-ai 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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Merged via the queue into main with commit a1a8fe5 Jun 30, 2026
39 checks passed
@edgarrmondragon edgarrmondragon deleted the test/flattenning-benchamarks branch June 30, 2026 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant