microsoft / MapsSDK-Unity

This repository contains samples, documentation, and supporting scripts for Maps SDK, a Microsoft Garage project.
MIT License
650 stars 128 forks source link

How can we control the frequency of web requests? #209

Closed haldunkececigil closed 7 months ago

haldunkececigil commented 10 months ago

Hi there,

For network performance optimization purposes, we want to regulate the frequency of our web requests to Bing Maps. Our app, (running at 72 fps) frequently updates the map location (latitude, longitude, zoom) through user interaction, like panning and zooming. We’d like to keep updating the map coordinates each frame but want to limit the requests for new mesh and texture tiles to a custom frequency. Making web requests as few as four times per second could suffice. Ideally, we'd like to set this web request frequency to be at every nth frame via an external script.

Question 1: Can we configure web requests to execute only on selected frames? This could involve either aborting in-progress requests on frames we choose to skip or specifically triggering requests on designated frames. How might this be implemented?

Question 2: If the SDK currently doesn't support this, could you guide us on modifying scripts, like 'TileLayer', to achieve our goal? We're unsure how to proceed as the relevant code appears to be inaccessible.

Question 3: If the above isn't feasible (e.g., due to hidden code), could you provide us with a custom ‘TileLayer’ script (or other relevant script(s)) with the relevant code exposed? We believe reducing our web request count would be beneficial to both us and Bing Maps, as you know, web requests are not billable, only initializations are.

kircher1 commented 10 months ago

Hello, correct, there is no way to configure this unfortunately, but there are already various throttles used internally to limit both requests and processing workloads that happen in the main thread, idea being to meet a good tradeoff between loading speed and processing overhead.

If you have implemented some custom TextureTileLayer/ElevationTileLayers, then those implementations could always throttle requests themselves (e.g. use a semaphore in the GetTextureTile), but I'm not sure that applies.

A more immediate idea: If it is acceptable to have gaps in the map as data loads and your goal is to reduce networking overhead, you could set mapRenderer.RequestTilesAroundView to false. That should get rid of a chunk of requests that prospectively load tiles which aren't visible but around the current map extents.

One last thought, all the map data related network requests go through UnityWebRequest API-- maybe there is a way to configure a throttle for that globally?