Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use linked list in ReleasePool #281

Merged
merged 7 commits into from
Nov 24, 2018
Merged

Use linked list in ReleasePool #281

merged 7 commits into from
Nov 24, 2018

Conversation

kngwyu
Copy link
Member

@kngwyu kngwyu commented Nov 18, 2018

Fix #271
I haven't benched yet and maybe LinkedList<[NonNull<_>; 256] or so is more efficient

@kngwyu kngwyu changed the title [WIP] Use linked list in ReleasePool Use linked list in ReleasePool Nov 18, 2018
@kngwyu kngwyu changed the title Use linked list in ReleasePool [WIP] Use linked list in ReleasePool Nov 18, 2018
@kngwyu kngwyu requested a review from konstin November 18, 2018 10:18
@kngwyu
Copy link
Member Author

kngwyu commented Nov 18, 2018

The 1st commit is naive LinkedList<NonNull<PyObject>> implementation.
The 2nd & 3rd commit is LinkedList<[NonNull<PyObject>; 256]> implementation.
I'll note a benchmark result for both two.

@kngwyu
Copy link
Member Author

kngwyu commented Nov 18, 2018

Benchmark result:
Vec<NonNull<_>>(before)

running 1 test
test iter_dict ... bench:   1,943,691 ns/iter (+/- 53,443)

LinkedList<NonNull>(after: 1)

running 1 test
test iter_dict ... bench:   6,349,135 ns/iter (+/- 259,604)

LinkedList<[NonNull<_>; 256>(after: 2)

running 1 test
test iter_dict ... bench:   2,172,151 ns/iter (+/- 248,869)

LinkedList<[NonNull<_>; 512]>(Not pushed)

running 1 test
test iter_dict ... bench:   2,325,197 ns/iter (+/- 110,542)

(Arch Linux 4.18.16, rustc 1.32.0-nightly (25a42b2ce 2018-11-07), Intel Core i5-6500)

@kngwyu kngwyu changed the title [WIP] Use linked list in ReleasePool Use linked list in ReleasePool Nov 18, 2018
// release py objects
for ptr in vec.iter_mut() {
// release PyObjects
for ptr in vec.iter() {
ffi::Py_DECREF(ptr.as_ptr());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #282 because this is lurking UB

Copy link
Member

@konstin konstin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big thanks for tackling this!

I wonder if there's a performance overhead in using a vec or zero-initialization. This would allow us to avoid mem::uninitialized()

@kngwyu
Copy link
Member Author

kngwyu commented Nov 21, 2018

@konstin
Benchmark result:
[T; 256]

running 1 test
test iter_dict ... bench:   2,222,297 ns/iter (+/- 69,061)

Vec built by Vec::with_capacity(256) (https://github.com/kngwyu/pyo3/tree/list-vec)

running 1 test
test iter_dict ... bench:   2,591,632 ns/iter (+/- 166,590)

(Ubuntu 17.10 + AMD Ryzen 5 1600)

@konstin
Copy link
Member

konstin commented Nov 24, 2018

Thanks for measuring, we now have a good rationale for keeping mem::uninitialized().

@konstin konstin merged commit 9938eb9 into PyO3:master Nov 24, 2018
konstin added a commit that referenced this pull request Nov 25, 2018
konstin added a commit that referenced this pull request Nov 25, 2018
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.

None yet

2 participants