Skip to content

perf(ordinal-patterns): serial path for small data and bypass decorator overhead - #53

Merged
cbueth merged 3 commits into
mainfrom
perf/ordinal-patterns-serial-path
Jul 30, 2026
Merged

perf(ordinal-patterns): serial path for small data and bypass decorator overhead#53
cbueth merged 3 commits into
mainfrom
perf/ordinal-patterns-serial-path

Conversation

@cbueth

@cbueth cbueth commented Jul 30, 2026

Copy link
Copy Markdown
Owner

This PR introduces two changes to the COP (Continuous Ordinal Patterns) connectivity metric:

  1. Serial path for small data: norm_windows and pattern_distance used numba parallel=True with prange, spawning OpenMP threads on every call. For small benchmark data (ts_len=50, p_size=3 -> 48 windows), 91% of execution time was OpenMP thread synchronization. Split each into serial (@njit with range) and parallel (@njit with prange) variants, with a plain-Python dispatcher choosing the serial path when n_windows < 200. pattern_transform_2d no longer needs @njit since it delegates to the dispatchers.

  2. Decorator bypass: random_patterns called gt_multi_lag (wrapped in @connectivity) inside its per-pattern loop, incurring inspect.signature().bind() overhead for every random pattern. Call find_optimal_lag(gt_single_lag, ...) directly instead. No redundant validation.

Also adds two test types:

  • Random-noise tests that verify norm_windows and pattern_distance against a numpy independent reference implementation.
  • Serial-vs-parallel equivalence tests confirming both paths produce identical output on >200-window data.

@cbueth cbueth self-assigned this Jul 30, 2026
@cbueth cbueth added the enhancement New feature or request label Jul 30, 2026
@codspeed-hq

codspeed-hq Bot commented Jul 30, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×3.5

⚡ 2 improved benchmarks
✅ 26 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
test_ordinal_patterns 15.9 ms 1.9 ms ×8.1
test_detrend_method[z_score-p10] 2.1 ms 1.3 ms +53.09%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing perf/ordinal-patterns-serial-path (4858190) with main (875adcd)

Open in CodSpeed

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (875adcd) to head (4858190).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #53   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           29        29           
  Lines          842       849    +7     
  Branches       151       152    +1     
=========================================
+ Hits           842       849    +7     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cbueth
cbueth merged commit 47c2e2d into main Jul 30, 2026
12 checks passed
@cbueth
cbueth deleted the perf/ordinal-patterns-serial-path branch July 30, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant