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

Track patients with unordered_set rather than vector #1253

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

jagerman
Copy link
Member

@jagerman jagerman commented Jan 13, 2018

The stored vector of pybind-registered-type patients can grow without
bound if a function is called with the same patient multiple times.

This commit changes the pybind internal patient storage to an
unordered_set to avoid the issue.

Fixes #1251

I've also pushed a separate fix for 2.2.2 (in #1250) that solves this by walking through the vector to avoid storing a duplicate. (It's not as nice a fix, but it doesn't require changing the internals structure for 2.2.2).

EDIT(eric): #2289 is an alternative or precursor to this PR.

The stored vector of pybind-registered-type patients can grow without
bound if a function is called with the same patient multiple times.

This commit changes the pybind internal patient storage to an
`unordered_set` to avoid the issue.

Fixes pybind#1251
@jagerman jagerman added this to the v2.2.2 milestone Jan 13, 2018
@jagerman jagerman mentioned this pull request Jan 13, 2018
@jagerman jagerman modified the milestones: v2.2.2, v2.3 Feb 18, 2018
@wjakob
Copy link
Member

wjakob commented Jun 30, 2020

Hi @jagerman -- sorry for not getting to this (now-ancient PR) earlier. This is just to say that your change looks good to me. We could merge it to master and consider it for inclusion to the next minor version. Would you be able to address the conflicts?

@EricCousineau-TRI
Copy link
Collaborator

I'm briefly trying to see if I can update this PR, resolving merge conflicts, per discussion in #1251.

(For now, will do fast-forward merge)

@EricCousineau-TRI EricCousineau-TRI self-requested a review July 10, 2020 15:46
- Checks `not m.has_patients()` after nurse is gc'd
- Uses Python implementation of `refcount`
EricCousineau-TRI pushed a commit to EricCousineau-TRI/pybind11 that referenced this pull request Jul 10, 2020
This fixes pybind#1251 (patient vector grows without bounds) for the 2.2.2
branch by checking that the vector doesn't already have the given
patient.

This is a little less elegant than the same fix for `master` in pybind#1253 (which
changes the patients `vector` to an `unordered_set`), but that requires
an internals layout change, which this approach avoids.
@EricCousineau-TRI
Copy link
Collaborator

Filed #2289 per @YannickJadoul's request:
#1251 (comment)

My pref is on this PR, if we think it'll be more efficient.
However, I will defer to y'all on which one y'all want!

@YannickJadoul
Copy link
Collaborator

Same thing as before: depends on whether/when we want to break the internal ABI ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using py::keep_alive<N, P>() may cause internals.patients[nurse] to grow without bounds
5 participants