mapbox / vector-tile-cs

Parses vector tiles with C#.
BSD 3-Clause "New" or "Revised" License
57 stars 37 forks source link

CPU and memory profiling #17

Open wilhelmberg opened 7 years ago

wilhelmberg commented 7 years ago

Initial micro optimization are done: https://github.com/mapbox/vector-tile-cs/issues/15#issuecomment-258843441 https://github.com/mapbox/vector-tile-cs/pull/16

Revisit after https://github.com/mapbox/vector-tile-cs/issues/12 https://github.com/mapbox/vector-tile-cs/issues/7 https://github.com/mapbox/vector-tile-cs/issues/3

wilhelmberg commented 7 years ago

Working on refactoring to full lazy decoding (branch 'breakout-full-decoding') and looking at profiling now:

Ran through the 210 streets+terrain tiles of mvt-bench-fixtures 100 times (equals decoding of 21,000 tiles).

Results of bench.exe on my MacBook (compiled with Release, with Debug it takes roughly twice the time):

runs:100
tiles per run:210
min [ms]:240
max [ms]:304
avg [ms]:262,17
StdDev:12,52
overall [ms]:26217

This means decoding all 210 tiles of the repo takes on average 0.262 seconds.

@springmeyer wrt optimizations we talked about, there doesn't seem to be a lot of potential for improvement: image

Varint() stands out with 23% but it also gets called 365.916.233 times.

Might be worth to implement differently, Assembler maybe 😏 - but that would probably not be cross platform.


Next steps

wilhelmberg commented 7 years ago

🎉 🎆 25% faster!

Some more profiling revealed why Variant() showed up high: It was the Position property of PbfReader that gets called a lot. Changed the property to a private field and speed increased by 2 seconds.

Did some other minor changes and decoding of 21,000 tiles is now down to 19.6 seconds from 26.2 before, meaning +1,000 tiles/sec:

runs          : 100
tiles per run : 210
min [ms]      : 186
max [ms]      : 250
avg [ms]      : 196,93
StdDev        : 14,12
overall [ms]  : 19693
tiles/sec     : 1066,3

I suggest we leave as is for now, until we get some feedback that we need to squeeze out more performance. Will clean up and PR next week.


Didn't find a way to improve Varint():