Skip to content

Reduce Python overhead in idwtn coefficient handling - #892

Open
dexhunter wants to merge 1 commit into
PyWavelets:mainfrom
dexhunter:perf/idwtn-coefficients
Open

dexhunter wants to merge 1 commit into
PyWavelets:mainfrom
dexhunter:perf/idwtn-coefficients

Conversation

@dexhunter

Copy link
Copy Markdown

iswt2 makes many small idwtn calls, where coefficient validation and Python bookkeeping account for a substantial part of the runtime. This change removes the duplicate None filter, replaces NumPy uniqueness with a Python set for key lengths, reuses the validated key length and shapes, and reduces temporary key lists and repeated lookups during reconstruction. Subbands are still reconstructed in lexicographic order, with the existing dtype promotion.

For swt_benchmarks.Iswt2TimeSuite.time_iswt2(16, 'haar'):

Baseline Patched Time reduction
11.554 ms/call 8.564 ms/call 25.9%

Measured against commit c9b542b2d2c37d28ed1d9bd49d178d2769608905 using the repository's unchanged ASV benchmark, Python 3.12.13, NumPy 2.5.4, and ASV 0.6.6 on Linux x86_64. Both versions used the same isolated core and compiled extensions. ASV collected 27 samples per version across three rounds, with 10 calls per sample and a one-second warmup per round; coefficient setup was outside the timed method.

Three fresh paired harness runs on the broader seeded workload passed exact output comparisons, with candidate/baseline time ratios of 0.759462, 0.748694, and 0.782821 (median 0.759462). Each run used nine baseline/candidate pairs. These ratios describe the complete harness workload, separate from the single ASV case above.

Validation:

  • python -m pytest pywt/tests -q: 1,052 passed, 2 skipped on the patched source tree.
  • Additional baseline comparisons passed for coefficient conversion-error ordering, non-string coefficient-key errors, and empty-axes errors.
  • Patch whitespace check passed.

AI assistance: Weco (Claude Opus 5.5) generated optimization candidates; Codex assisted with selection, source review, benchmarking, testing, and this description.

Weco share link: https://dashboard.weco.ai/share/W-VopKsB0Xyzekg_9r9DquGM1nulxr6N

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.

1 participant