Skip to content
This repository was archived by the owner on Nov 25, 2019. It is now read-only.
This repository was archived by the owner on Nov 25, 2019. It is now read-only.

Improve Data Fetching in Unity #11

@david-rhodes

Description

@david-rhodes

TL;DR

Our current Unity implementation for making web requests is quite inefficient. Let's find ways to improve it.

Possible Inefficiencies

  • Web requests are using coroutines. Each coroutine allocates memory on the heap (every tick). Requesting hundreds of tiles will lead to "massive" GC spikes.
  • Requests are not threaded.
  • Each low level object that wants to make a request needs a FileSource. This is often duplicated between objects. Unknown what the correct solution is, but probably depends on our threading options.
  • Currently, response errors are handled as strings. String compares are expensive and prone to error.

Other Considerations

  • Coroutines do not operate (sans hacks) at edit time. This makes it difficult to perform requests outside of "play" mode.
  • I expect developers to hit their rate limits quite easily. It would be nice if we offered a convenience layer to automatically handle the distribution of requests or re-queuing of requests on rate limit exceeded errors. Of course a lot of developers will implement their own version of this to suit their needs, but ours may serve as a solid starting point.
  • Web requests should have timeouts (I have, on occasion, observed requests never providing a response).

Possible Solutions

  • Use something like More Effective Coroutines (note: unsure if this will also solve the editor coroutine issues, but it could since you don't need to inherit from MonoBehaviour).
  • Use C# Threads.
  • Use System.Web for web requests (possibly less overhead).
  • @BergWerkGIS mentioned using BruTile as a possible library for managing batch requests.

Next Steps

It would be great to have a C# expert (@BergWerkGIS, I'm looking at you) experiment in this area.

/cc @mapbox/games

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions