Azure-Samples / Azure-Samples/azure-maps-leaflet

Plugin is causing high CPU usage

Open
#9 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
22
Forks
10
PR merge metrics
No merged PRs in 30d

Description

### This issue is for a:
```
- [x] bug report
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)
```

### Minimal steps to reproduce
- Go to any implementation of Leaflet with Azure Map tiles (eg. [this Azure Map Sample](https://samples.azuremaps.com/third-party-map-controls/render-azure-maps-in-leaflet)).
- Check the tab CPU usage in the browser task manager (Shift+Escape on Chromium based browsers)
- The CPU is at 100% continuously which affects both the browser and the system performance

### Expected/desired behavior
The map should not be consistently use 100% of the browser CPU

### Versions
Reproducible using the latest version of the plugin and the latest version of Leaflet (1.9.4 as of today)

### Mention any other details that might be useful
Web Workers have been introduced in [this PR](https://github.com/Azure-Samples/azure-maps-leaflet/issues/3) on July 29, 2022 to fix the issue that setTimeout is not called when the tab is inactive.
The worker code contains this line of code `while (Date.now() < before + delay) { };` which starts an infinite loop until the number of milliseconds defined in `delay` is elapsed. This infinite recursion is responsible for the high CPU usage.

I suggest to reimplement the web worker with a proper implementation.
I can make a PR to fix this issue.

Contributor guide

Open the contributing guide

Research direction

Start with the Web Worker code introduced in the linked issue/PR #3 and inspect the busy-wait loop described in this report. Reproduce the issue with the Azure Maps Leaflet sample and verify that the plugin no longer keeps the browser CPU at 100% while preserving the worker's timing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, typescript
Domain
frontend, performance, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.