Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Avoid loading style source if its layer(s) are not shown#3095

Merged
brunoabinader merged 3 commits into
masterfrom
3095-avoid-loading-source-if-layers-are-not-shown
Dec 18, 2015
Merged

Avoid loading style source if its layer(s) are not shown#3095
brunoabinader merged 3 commits into
masterfrom
3095-avoid-loading-source-if-layers-are-not-shown

Conversation

@brunoabinader
Copy link
Copy Markdown
Contributor

Given https://github.com/mapbox/mapbox-gl-styles/blob/master/styles/satellite-hybrid-v8.json as example of a style containing 2+ sources, if all layers related to a specific source are either disabled (e.g. due to class selections) or invisible, we should avoid loading the style source entirely. This saves processing time and network bandwidth.

When the layers related to a specific style source are re-enabled, the burden of loading the style source could be reduced by using a cache file source.

/cc @mapbox/gl @mapbox/mobile

Comment thread src/mbgl/style/style_layer.hpp Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rename this to isVisible and reverse the boolean, for consistency with "visibility" as from the style spec.

@jfirebaugh
Copy link
Copy Markdown
Contributor

Instead of introducing more state, can we use Source::enabled for this?

@brunoabinader brunoabinader force-pushed the 3095-avoid-loading-source-if-layers-are-not-shown branch from 871d08c to e939d94 Compare December 16, 2015 01:27
@brunoabinader
Copy link
Copy Markdown
Contributor Author

Instead of introducing more state, can we use Source::enabled for this?

Indeed, enabling the source only if the layer is visible in Style::recalculate() is nicer than comparing strings in Style::loadSources(). However, we still require Source::isLoading() to avoid double requests and StyleLayer::isVisible() because each StyleLayer-derived class calculates its visibility in a different way. I'll update the code accordingly.

@brunoabinader brunoabinader force-pushed the 3095-avoid-loading-source-if-layers-are-not-shown branch 2 times, most recently from 0194d2f to f57e025 Compare December 16, 2015 01:54
@jfirebaugh
Copy link
Copy Markdown
Contributor

There are some corner cases where a layer with a zero-opacity color still renders something, e.g. symbols with halo but transparent fill, background-pattern, outline-only fill layers. Can we limit the check to opacity > 0? Also we should add checks of the *-visibility layout property, which is the most common way to hide a layer completely.

@jfirebaugh
Copy link
Copy Markdown
Contributor

Can we make layer.isVisible() equivalent to layer.passes != RenderPass::None?

@brunoabinader brunoabinader force-pushed the 3095-avoid-loading-source-if-layers-are-not-shown branch 2 times, most recently from 670287a to b52d195 Compare December 16, 2015 18:55
Comment thread src/mbgl/map/source.cpp Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be a one liner: return !loaded && req.operator bool();

@brunoabinader brunoabinader force-pushed the 3095-avoid-loading-source-if-layers-are-not-shown branch from 3999815 to 919ef3b Compare December 17, 2015 20:30
@brunoabinader
Copy link
Copy Markdown
Contributor Author

Can we limit the check to opacity > 0?
Also we should add checks of the *-visibility layout property, which is the most common way to hide a layer completely.

This is used in Style::recalculate() now:

bool StyleLayer::needsRendering() const {
    return passes != RenderPass::None && visibility != VisibilityType::None;
}

I had to fix/modify some style unit tests to adapt to the new scheme for source loading - instead of immediately load sources upon style JSON parsing, we wait to check whether a layer actually needs it.

Comment thread src/mbgl/map/source.cpp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this change necessary? I would expect Source:isLoaded() to return true in the case that at some zN, it was enabled and loaded, and then at zM the only layer that used it becomes hidden and the source was therefore disabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed about enabled, but I believe we also should check if there is a pending request, which indicates the source is in loading state.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't req imply !loaded though? loaded only gets set to true after all the requests are successful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes 🎯 Good catch, indeed!

@brunoabinader brunoabinader force-pushed the 3095-avoid-loading-source-if-layers-are-not-shown branch 2 times, most recently from b37a4af to f270ef6 Compare December 17, 2015 22:41
@brunoabinader brunoabinader force-pushed the 3095-avoid-loading-source-if-layers-are-not-shown branch from f270ef6 to 9d3fe01 Compare December 18, 2015 00:53
@brunoabinader brunoabinader merged commit 9d3fe01 into master Dec 18, 2015
@brunoabinader brunoabinader deleted the 3095-avoid-loading-source-if-layers-are-not-shown branch December 18, 2015 01:30
jfirebaugh added a commit that referenced this pull request Apr 25, 2017
This reverses #3095. Rationale:

* We're now exposing source attributes as a public API. Making those attributes unavailable at certain times complicates that API.
* We're preparing to split RenderSource out of Source. Removing this removes a point of coupling between the two.
jfirebaugh added a commit that referenced this pull request Apr 26, 2017
This reverses #3095. Rationale:

* We're now exposing source attributes as a public API. Making those attributes unavailable at certain times complicates that API.
* We're preparing to split RenderSource out of Source. Removing this removes a point of coupling between the two.
jfirebaugh added a commit that referenced this pull request May 1, 2017
This reverses #3095. Rationale:

* We're now exposing source attributes as a public API. Making those attributes unavailable at certain times complicates that API.
* We're preparing to split RenderSource out of Source. Removing this removes a point of coupling between the two.
jfirebaugh added a commit that referenced this pull request May 2, 2017
This reverses #3095. Rationale:

* We're now exposing source attributes as a public API. Making those attributes unavailable at certain times complicates that API.
* We're preparing to split RenderSource out of Source. Removing this removes a point of coupling between the two.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants