fix(core): optimize FFI crossings, cache facade sizes, and clarify benchmarks/myths#24
Merged
Conversation
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| C & C++ | Jul 2, 2026 6:08a.m. | Review ↗ | |
| Rust | Jul 2, 2026 6:08a.m. | Review ↗ | |
| Python | Jul 2, 2026 6:08a.m. | Review ↗ |
Important
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This Pull Request resolves performance bottlenecks in PySTL's Rust extension and Python facades by reducing Python-Rust boundary crossings and adding native type-extraction comparison fast-paths. It also updates the benchmarks and documentation to provide fair algorithmic comparisons.
Key Changes
1. Rust Core & Algorithm Optimizations (
src/lib.rs)i64,f64,&str) inPyObjectOrd'seqandcmpimplementations. For common primitives, this avoids holding the GIL and crossing the FFI boundary for CPython rich comparison slots.lower_bound,upper_bound,binary_search,equal_range) to extract thePyListinto a RustVec<PyObject>once at the entry point. Element indexing is now done natively in Rust (&vec[mid]), avoidingpyobject_lt,pyobject_gt, andpyobject_eqhelpers to speed up comparators.2. Python Facade Optimizations (
pythonstl/facade/)self._sizecache tostack,queue, andvectorclasses..empty(),.size(), and pop validation checks to read from the cached size instead of making FFI calls, reducing boundary crossings from 2 to 1 (or 0) for operations likepop(),top(), andempty().3. Benchmarks & Documentation Clarity
benchmark_map.py,benchmark_stack.py, andbenchmark_vector.pyto compare:use_rust=True)use_rust=False)sys.path.insertblock to benchmark files so they target local development code instead of falling back to globally installedsite-packages.Verification & Benchmarks
1. Test Suite
pytestsuccessfully: 83 passed in 0.58s (down from 1.37s).2. Speedups Achieved (Rust vs. Pure Python STL)
at): Rust backend is 1.48x faster.