Stack allocate 2d points using tiny_vec. #222
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CHANGES.md
if knowledge of this change could be valuable to users.Position
, which is the fundamental unit for all the various geojson geometries, is currently represented as a (heap allocated)Vec
. This PR swaps it out to be aTinyVec
which can be stack allocated up to a certain number of elements, before moving to the heap.This PR also makes that fact private so we can make similar changes in the future in a non-breaking way.
Unlike #218, this branch maintains the ability to have n-dimensional points, building upon the branch I started in this comment.
This is a breaking change (maybe a substantial one for people relying on the Position type, but shouldn't affect people who are only using the high level APIs.). Switching to tiny_vec will be breaking for these people regardless, and the upside to making the struct opaque like this is that we can now more freely muck about with the internals, e.g. if we one day want to replace tiny_vec, or add a feature flag which allocates 3d stack allocations rather than 2, etc.
We could add a macro like
geojson::position![1.0, 3.0]
if people think thePosition::from([1.0, 3.0])
is too verbose.What do people think? I've wanted to do something like this for a long time, but kind of avoided it because it's a breaking change, and going to be annoying for anyone who was accessing the Position type directly.
I've tried to alleviate this a bit by implementing
Index/Mut
on Position. Are there other things I could do to make it break less? If you have a crate that uses geojson, I'd love to have some test cases to integrate this against to see how annoying it is.bench improvements look similar, but slightly less than #218