Skip to content
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

Use the reloadTile worker method if GeoJSON tile is already loaded #4069

Merged
merged 3 commits into from
Jun 10, 2017

Conversation

ezheidtmann
Copy link
Contributor

@ezheidtmann ezheidtmann commented Jan 31, 2017

During a style update, the source is reloaded. Because GeoJSONSource always calls loadTile in the worker, this means that any style change causes all tile PBFs to be regenerated. This makes hover effects on geojson sources very slow.

This PR fixes the performance issues by using the reloadTile worker method, just as in VectorTileSource. I believe we don't need to worry about the loading state because the GeoJSONSource#loadVectorData calls its callback synchronously, so there's only two branches here.

These changes perform very well in my use case but is relatively untested.

Symptomatically related to issues discussed here: #2874

Thanks a lot, yall!

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs
  • post benchmark scores
  • manually test the debug page

@ezheidtmann
Copy link
Contributor Author

jsfiddle showing extreme slowness http://jsfiddle.net/vk2knag7/1/

@ezheidtmann
Copy link
Contributor Author

There was a bug when setData is called -- tiles were not reset; just pushed one possible workaround. I don't know a lot about mapbox-gl-js internals so I bet there's a more elegant way to do it.

@ezheidtmann
Copy link
Contributor Author

CI failed on lint, fixed and re-running.

@Scarysize
Copy link

Nice! We ran into this issue with a circle layer & using map.setFilter. We ended up with just using source.setData with the single hovered GeoJSON feature on the highlight layer.

@mourner
Copy link
Member

mourner commented Feb 1, 2017

This is great!

  • Is there a way to add tests to make sure this doesn't regress?
  • Are there any race conditions to be aware of when calling setData and reloading tiles at the same time?

@mourner mourner added the performance ⚡ Speed, stability, CPU usage, memory usage, or power usage label Feb 1, 2017
@ezheidtmann
Copy link
Contributor Author

Thanks!

Re races: I don't see an opportunity for a race between those two; the geojson index and the this.loaded cache are changed at the same time, so I would guess as long as there wasn't a race before, there isn't one now. But as I say, I'm not really familiar with this code.

Re tests: Not sure how to test this but hopefully others with more experience can fill this in.

@mourner
Copy link
Member

mourner commented Apr 25, 2017

Hey @ezheidtmann, let's work together on shipping this PR! Want to rebase against the current master as the first step?

@ezheidtmann ezheidtmann force-pushed the geojson-reload-tile branch from 5a5cf36 to 8a9051b Compare June 9, 2017 18:46
@ezheidtmann
Copy link
Contributor Author

Hey @mourner sorry for the long silence, I've been buried in other work during Bike Month. I rebased and it looks good; I can test later today that my app still has acceptable performance.

Re tests: To guard against regressions, we can test that reloadTile is called appropriately, or we can test that the overall performance is acceptable (hard?), or maybe there is something even better we could do?

@mourner
Copy link
Member

mourner commented Jun 9, 2017

@ezheidtmann great, no worries! Re tests, I think it's enough to make sure tile is reloaded. We can cover benchmarking separately later.

@ezheidtmann
Copy link
Contributor Author

I wrote a test. It took me a lot of time. I hope it is not absurd or wrong.

@ezheidtmann ezheidtmann force-pushed the geojson-reload-tile branch from c811f9c to 5065507 Compare June 10, 2017 00:11
Copy link
Member

@mourner mourner left a comment

Choose a reason for hiding this comment

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

Wow, that was indeed quite difficult! Thanks for taking the time to do that — highly appreciated. And sorry that it too so long.

@mourner mourner merged commit 4fcbf38 into mapbox:master Jun 10, 2017
@ezheidtmann
Copy link
Contributor Author

👍 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance ⚡ Speed, stability, CPU usage, memory usage, or power usage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants