diff --git a/crates/accelerate/src/quantum_circuit/py_ext.rs b/crates/accelerate/src/quantum_circuit/py_ext.rs index 3ceeefbcc6c8..da27764a7f4e 100644 --- a/crates/accelerate/src/quantum_circuit/py_ext.rs +++ b/crates/accelerate/src/quantum_circuit/py_ext.rs @@ -9,6 +9,17 @@ // Any modifications or derivative works of this code must retain this // copyright notice, and modified files need to carry a notice indicating // that they have been altered from the originals. +//! Contains helper functions for creating [Py] (GIL-independent) +//! objects without creating an intermediate owned reference. These functions +//! are faster than PyO3's list and tuple factory methods when the caller +//! doesn't need to dereference the newly constructed object (i.e. if the +//! resulting [Py] will simply be stored in a Rust struct). +//! +//! The reason this is faster is because PyO3 tracks owned references and +//! will perform deallocation when the active [GILPool] goes out of scope. +//! If we don't need to dereference the [Py], then we can skip the +//! tracking and deallocation. + use pyo3::ffi::Py_ssize_t; use pyo3::prelude::*; use pyo3::types::{PyList, PyTuple};