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
support caching of VectorTileFeature
s resolved for a ThemeLayer
#4
support caching of VectorTileFeature
s resolved for a ThemeLayer
#4
Conversation
@blaugold this is very cool! Nice work. Great to see how a benchmark reveals the results of the improvement that you made! I've been thinking about this problem but haven't come up with a great solution yet. I've run the profiler with two different tilesets and two different themes, and found that the results are quite different:
The highlighted (turquoise) stack element in both profiler snapshots is the selector function, i.e. the performance cost addressed in this PR. My initial take on this is that the zoomstack theme attempts to render a lot more text - which is very expensive due to The high cost of selecting tile features appears to be related to two issues:
The good thing about caching is that we can avoid performing these calculations more than once. The downside is that we have to calculate them once. From what I can gather from reading the code in this PR, that occurs in the preprocessor, which is really nice. Unfortunately preprocessing still runs on the UI thread (just not when rendering a frame). Alternatives to caching include making Some thoughts about the implementation of this PR specifically: How do you envision clients of this library managing the lifecycle of Did you consider reworking There appears to be some boilerplate in here that could be avoided by using a benchmarking library such as benchmark_harness or benchmark. Any reason not to use one of those? |
Probably unrelated to this, but I noticed dart-vector-tile-renderer/lib/src/features/symbol_point_renderer.dart Lines 42 to 43 in b700a0f
As it is currently implemented, to make use of caching, you create a In general, everything that is not touching
That's true, and
I expected a widget, for example, which is rendering one or more tiles to evict the cached data when it is disposed.
I'm always hesitant to add a dependency for something basic, but looking at |
d9a37f1
to
d2a6527
Compare
d2a6527
to
9fb79e1
Compare
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.
Looks great! A few comments inline.
lib/src/tileset.dart
Outdated
@@ -8,11 +9,17 @@ import 'themes/theme_layers.dart'; | |||
class Tileset { | |||
final bool preprocessed; | |||
final Map<String, VectorTile> tiles; | |||
late final ThemeLayerFeatureResolver resolver; |
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.
is late
needed?
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.
Yes, because we need to access this
to initialize resolver
. That means we cannot initialize before the constructor body.
Excellent work, thanks so much for the contribution. |
Glad I can contribute. Let me know if there is something I could help with. |
you might want to take a look at this concurrency experiment see the commit message - there's potentially more that could be done to improve the frame rate by offloading work to an isolate as you suggested previously feel free to create issues to initiate a discussion or track any work that you take on. |
…reensopinion#4) feat: support caching of `VectorTileFeature`s resolved for a `ThemeLayer`
While doing some profiling, I found that around half of the time spent in
Renderer.render
is evaluatingThemeLayer
filters to resolve the features to render for aThemeLayer
. Since themes and tile sets are immutable, it should be possible to cache the resolved features for aTileset
andThemeLayer
pair.This PR adds a benchmark, which shows that rendering time of a
Tileset
is cut in half, when this new caching is used:Let me know what you think.