mapbox / mapbox/vtshaver

Optimization idea: avoid serialize and compress if we've shaved nothing

Open
#5 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue
Dominant language
JavaScript
Stars
44
Forks
7
PR merge metrics
No merged PRs in 30d

Description

Per @springmeyer 's thoughts:

A potential optimization to look into would be:

- Track if we don't ever shave any data off a tile
- In that case, return early without serializing the newly created tile

The early return would save the call to `finalvt.serialize` and to compression (if compression is requested). The largest performance gain would likely come from skipping compression (if it is requested) since we've learned from profiling in api-maps[citation needed] that compression of large tiles can be more expensive than the vtile encoding of layers+features.

So, we'd be able to skip these calls in the case that we've not actually been able to shave any data https://github.com/mapbox/vtshaver/blob/809ba394821fc243bba308be0ed079d4c5743147/src/shave.cpp#L405-L410. In this case we could return nothing for the resultant buffer as an indication that the caller should simply re-use the data passed into the shaver for that tile.

I'm basing this optimization idea on the assumption that, while potentially uncommon or rare, it is possible (and frequent enough to matter for large scale performance) that you might have a vector tileset with some tiles which get a lot shaved off and some tiles that get nothing shaved off.

Before ever moving on this feature however we should do some research to figure out of this "did not shave anything" scenario actually happens in reality and if it does whether it happens with data the is large enough to have measurable cost to `serialize` and `compress`. If these things don't happen then this optimization would likely have no benefit.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/shave.cpp around lines 405-410 and inspect how tile data reaches serialization and compression. First determine whether tiles commonly have no data shaved and whether those tiles are large enough for skipping serialize or compression to matter. Done means the scenario and performance impact are measured well enough to decide whether this optimization is worthwhile.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.