Skip to content

Conversation

@avaitla
Copy link

@avaitla avaitla commented Dec 29, 2025

This adds a high-performance Rust backend for portion that can be used to speed up interval operations by 10-1000x depending on the operation.

Key changes:

  • rust_core/: PyO3-based Rust implementation of Interval operations

    • BoundType enum (Closed/Open)
    • Value enum (NegInf/Finite/PosInf)
    • Atomic struct for single intervals
    • Interval struct for union of atomic intervals
    • All core operations: union, intersection, complement, difference
    • Python bindings with RustInterval and helper functions
  • benchmark.py: Performance comparison script showing speedups:

    • Interval creation: 22-40x faster
    • Intersection: 850-1100x faster
    • Union: 9-42x faster
    • Complement: 430-800x faster
    • Containment checks: 12-15x faster
    • Difference: 740-1090x faster
    • Real-world mixed operations: 50-52x faster

Build and install with:
cd rust_core && maturin build --release
pip install target/wheels/*.whl

Usage:
import portion_rust as PR
interval = PR.rust_closed(0, 10) | PR.rust_closed(20, 30)

This adds a high-performance Rust backend for portion that can be used
to speed up interval operations by 10-1000x depending on the operation.

Key changes:
- rust_core/: PyO3-based Rust implementation of Interval operations
  - BoundType enum (Closed/Open)
  - Value enum (NegInf/Finite/PosInf)
  - Atomic struct for single intervals
  - Interval struct for union of atomic intervals
  - All core operations: union, intersection, complement, difference
  - Python bindings with RustInterval and helper functions

- benchmark.py: Performance comparison script showing speedups:
  - Interval creation: 22-40x faster
  - Intersection: 850-1100x faster
  - Union: 9-42x faster
  - Complement: 430-800x faster
  - Containment checks: 12-15x faster
  - Difference: 740-1090x faster
  - Real-world mixed operations: 50-52x faster

Build and install with:
  cd rust_core && maturin build --release
  pip install target/wheels/*.whl

Usage:
  import portion_rust as PR
  interval = PR.rust_closed(0, 10) | PR.rust_closed(20, 30)
@avaitla avaitla closed this Dec 29, 2025
@AlexandreDecan
Copy link
Owner

Any human comment on this?

@avaitla
Copy link
Author

avaitla commented Jan 4, 2026

Thanks for the work on this it's very useful for us. Apologies it was a mistake to open this PR back to the main repo. We use this library but have a lot of intervals and found the bottleneck to be here. I've been implementing in rust we only need date time intervals and didn't mean to make a pr back into main branch.

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.

3 participants