-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance improvement #161
Conversation
🤔 maybe instead of introducing breaking change I can update the functions called by |
0dec372
to
3a8bed8
Compare
with last commit
I've reverted the change to |
origin_x | ||
+ (math.floor(t.x / cf) + 1) * matrix.cellSize * cf * matrix.tileWidth | ||
) | ||
bottom = origin_y - (t.y + 1) * matrix.cellSize * matrix.tileHeight |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do all the calculation here instead of calling _ul
and _lr
method which will duplicate some stuff (matrix lookup, origin, coalecense)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cons: we end up having duplicated code
t = _parse_tile_arg(*tile) | ||
_left, _bottom, _right, _top = self.xy_bounds(*tile) | ||
left, top = self.lnglat(_left, _top) | ||
right, bottom = self.lnglat(_right, _bottom) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the fastest
xy_bounds
methods instead of ul
and lr
methods
@@ -765,9 +771,8 @@ def custom( | |||
|
|||
def matrix(self, zoom: int) -> TileMatrix: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use lru_cache here?
I've read some article that mentioned that using lru cache for class method might result in memory leaks 🤷
# main
%timeit tms.xy_bounds(1, 40, 7)
7.44 µs ± 45.8 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
# This PR
%timeit tms.xy_bounds(1, 40, 7)
3.8 µs ± 63.2 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) |
…into feature/performance-improvement
|
while working on #160 I wanted to see what were the bottleneck and found that the
TileMatrixSets.matrix(z: int)
method was the first method slowing things downIn this PR I'm adding a
_tile_matrices_idx: Dict[str, int]
private attribute, which will be used for faster lookup (using dictionary is faster than looping through a listThe second improvement proposed in this PR is the removal of duplicated calls to the
_parse_tile_arg
function by changing the input for the_ul/ul/_lr/lr
methods which accepted Tuple or Tile objects. They now require Tile object.results: