Skip to content

Guidance on exporting large nested Rust structs to Python #1961

Answered by mejrs
cswinter asked this question in Questions
Discussion options

You must be logged in to vote

We should probably add a section in the guide that discusses this stuff in depth.

To avoid this performance hit

You're going to have to take that hit somewhere on the Rust/Python boundary. You could allocate everything on the Python heap (so, you'd have Py<...> wrappers everywhere) which avoids the cloning but this just moves some cost to conversions when Rust code needs to work on the structs.

The simplest option might be to define getters on all members. However, unless I'm mistaken this would seem to require copying the entire substructure on each access which would make it very expensive to iterate over collections contained in the struct from Python code.

Also, it would return a …

Replies: 8 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by davidhewitt
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
Converted from issue

This discussion was converted from issue #1701 on October 31, 2021 16:10.