-
Notifications
You must be signed in to change notification settings - Fork 42
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
Tthread-local geos context #164
Tthread-local geos context #164
Conversation
To the actual code change: instead of allocating new geos contexts I'm just reusing the same thread-local contexts via |
let mut cy = 0.; | ||
|
||
let ret = GEOSSegmentIntersection_r( | ||
ctx.as_raw(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it needed here? Couldn't with_context
be called inside GEOSSegmentIntersection_r
methods directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GEOSSegmentIntersection_r
is a GEOS C API, how would that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah it's a function. My bad, then that answers my question.
This is super cool! Just one question and then seems ready for me to go. |
Again, great improvement, thanks! |
Thank you :) |
This PR is follow-up of my previous issue #141 and also reaction to #160. (I don't think there is a memory leak, but this PR does lower memory footprint of every geometry by little more than 1kB as that is roughly the size of geos context, which would be reused with my PR and not allocated for every geometry.)
I see geos context as just an implementation detail of propagating error messages from c++ geos exceptions through geos c api in reentrant way. To address questions in #141: I dont't think the context is useful from user's point of view and I would say it is better/simpler to not have it in public api at all. I also think that context should not be a property of geometry for the same reason (and because unnecessarily used memory). And also I don't see it useful to be able to set own error handler as the context is already used to propagate geos errors to
GResult
. The original c++ geos api has nothing like the context and also python geos wrappershapely
is using geos context only as an internal implementation detail and is not accessible to users.Another reason for this PR is that geos context is not thread-safe (it's not
Sync
), so this PR makes things correct. Although right now it seems that the worst case is possibly corrupted error message which is not severe problem really, but still.So this is my suggestion :)