Skip to content

2.x branch optimization #32

Description

@springmeyer

I noticed that layer_map<CoordinateType> decode_tile(std::string const& buffer) at

layer_map<CoordinateType> decode_tile(std::string const& buffer)
{
layer_map<CoordinateType> m;
vtzero::vector_tile tile(buffer);
while (auto layer = tile.next_layer())
{
mapbox::feature::feature_collection<CoordinateType> fc;
while (auto feature = layer.next_feature())
{
auto f = extract_feature<CoordinateType>(feature);
if (!f.geometry.template is<mapbox::geometry::empty>())
{
fc.push_back(f);
}
}
if (!fc.empty())
{
m.emplace(std::string(layer.name()), std::move(fc));
}
}
return m;
}
does not leverage pre-allocation optimizations. We should likely do:

diff --git a/include/mapbox/vector_tile.hpp b/include/mapbox/vector_tile.hpp
index c61640b..0e8c672 100644
--- a/include/mapbox/vector_tile.hpp
+++ b/include/mapbox/vector_tile.hpp
@@ -66,12 +66,13 @@ layer_map<CoordinateType> decode_tile(std::string const& buffer)
     while (auto layer = tile.next_layer())
     {
         mapbox::feature::feature_collection<CoordinateType> fc;
+        fc.reserve(layer.num_features());
         while (auto feature = layer.next_feature())
         {
             auto f = extract_feature<CoordinateType>(feature);
             if (!f.geometry.template is<mapbox::geometry::empty>())
             {
-                fc.push_back(f);
+                fc.push_back(std::move(f));
             }
         }

/cc @flippmoke to review and apply if this looks good.

Activity

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions