Skip to content

Conversation

@nrabinowitz
Copy link
Collaborator

Small optimizations for cellToVertex. The main benefit of this work was to identify the key perf bottleneck, which is the call to _h3ToFaceIjk in vertexRotations. The optimizations here are mainly to avoid expensive calls:

  • Skip calculating left and right neighbors if the origin is a center child (center children will always have the lowest index)
  • Skip calculating right neighbor if the left neighbor is a center child
  • For hexagon cells, use a simple direction lookup table to determine the reverse direction, instead of using the slightly slower directionForNeighbor.

This improves things, but doesn't add up as much as I'd like - approx 20% speedup:

Before

	-- cellToVertexes: 257.191600 microseconds per iteration (10000 iterations)
	-- cellToVertexesPent: 267.356200 microseconds per iteration (10000 iterations)

After

	-- cellToVertexes: 13.119300 microseconds per iteration (10000 iterations)
	-- cellToVertexesPent: 0.357300 microseconds per iteration (10000 iterations)
	-- cellToVertexesRing: 215.354700 microseconds per iteration (10000 iterations)
	-- cellToVertexesRingPent: 227.581100 microseconds per iteration (10000 iterations)

I think I can improve on this significantly by refactoring cellToVertexes to avoid repeated calculations for the origin and neighbors, but that will come in a later PR.

@coveralls
Copy link

coveralls commented Jan 21, 2021

Coverage Status

Coverage increased (+0.07%) to 99.25% when pulling 9038f7d on nrabinowitz:vertex-optimizations into dd0b1e5 on uber:master.

Copy link
Collaborator

@dfellis dfellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The overall complexity isn't much higher and the perf bump is good.

@nrabinowitz nrabinowitz merged commit b3a6a43 into uber:master Jan 22, 2021
@nrabinowitz nrabinowitz deleted the vertex-optimizations branch January 22, 2021 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants