Skip to content

Optimize MLX simulator hot paths - #7

Merged
cboulay merged 1 commit into
devfrom
perf/mlx-simulator-paths
Aug 24, 2026
Merged

cboulay merged 1 commit into
devfrom
perf/mlx-simulator-paths

Conversation

@cboulay

@cboulay cboulay commented Aug 24, 2026

Copy link
Copy Markdown
Member

Summary

  • compile and fuse the MLX cosine-encoding expression behind a lazy optional import
  • keep large MLX signals on-device when adding line noise, with a measured size gate for small messages
  • replace benchmark-style unit tests with state-aligned backend correctness tests
  • add a standalone streaming benchmark that evaluates each MLX chunk immediately

Profiling

Measured on an M4 Pro with MLX 0.31.2:

  • cosine encoder, 500 x 2 to 256: 690.8 us NumPy vs 177.0 us MLX, 3.90x speedup
  • dynamic colored noise, 50 x 8 to 15000: 1038.9 us NumPy vs 1076.9 us MLX, effectively neutral
  • line noise, 15000 x 256: 6078.4 us NumPy vs 476.4 us MLX, 12.76x speedup

The line-noise MLX path is gated at 200,000 signal elements because dispatch overhead loses below that crossover.

The colored-noise recurrence and baseline-drift hybrid prototypes were intentionally not moved to MLX: the real simulator shapes were faster with the existing Numba implementations.

Validation

  • 142 tests passed
  • ruff check passed
  • ruff format check passed
  • benchmark results validate NumPy and MLX outputs before reporting timings

@cboulay
cboulay merged commit 4f8725f into dev Aug 24, 2026
14 checks passed
@cboulay
cboulay deleted the perf/mlx-simulator-paths branch August 24, 2026 02:49
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