question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Location.watchHeadingAsync stalls the JS thread

See original GitHub issue

šŸ› Bug Report

Environment

Client version on iOS: 2.11.0.6067

$ expo diagnostics

Expo CLI 2.18.0 environment info:
    System:
      OS: macOS 10.14.4
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 11.14.0 - /usr/local/bin/node
      npm: 6.9.0 - /usr/local/bin/npm
    IDEs:
      Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
    npmPackages:
      expo: ^32.0.0 => 32.0.6 
      react: 16.5.0 => 16.5.0 
      react-native: https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz => 0.57.1 
    npmGlobalPackages:
      expo-cli: 2.18.0

Currently targeting iOS only, on my personal device (iPhone XS).

Steps to Reproduce

See lower for a repo + demo.

Basically: Bind anything except the simplest setState() to watchHeadingAsync and run it on a physical device. As soon as the device rotates, the JS thread drops dramatically.

Expected Behavior

Since watchHeadingAsync offers no built-in throttling (ex. only update on Ī” > 5°), it’s probably reasonable to expect a minimum of headroom in terms of CPU usage.

Actual Behavior

As soon as watchHeadingAsync is given a callback, the JS thread is at risk of dropping. Currently, writing my own throttling is already too heavy of a callback for a new iPhone XS to manage, and the JS thread can drop to 0 fps when the phone rotates slowly, even on a 20° throttle:

IMG_99DB1F1112C0-1

Reproducible Demo

Here is a barebones demo of the behavior. Only App.js is modified from expo init: https://github.com/L-A/expo-heading-demo/blob/master/App.js#L15-L18


export default class App extends React.Component {
  state = { heading: 0 };

  async componentDidMount() {
    let { status } = await Permissions.askAsync(Permissions.LOCATION);
    if (status === "granted") {
      Location.watchHeadingAsync(this.updateHeading);
    }
  }

  updateHeading = headingObject => {
    // console.log("Uncomment me to stall the JS thread on heading events");
    this.setState({ heading: headingObject.trueHeading });
  };

  render() {
    return (
      <View style={styles.container}>
        <Text>Orientation: {this.state.heading}</Text>
      </View>
    );
  }
}

I’d love to learn I’m just doing something wrong! However, the same code appeared to run without any issues around february this year. I’m having a hard time investigating what version introduced the issue since it’s on the Expo client’s side.

Cheers! I’d be happy to provide anything else that can help.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lukmccallcommented, Jul 23, 2019

@L-A Thanks you for checking it. I’m closing this issue. If the same situation will occur in the future, feel free to open issue again.

1reaction
L-Acommented, Jul 15, 2019

Hi @lukmccall! I’ll be able to test on a different phone and SDK 33 early next week, I’ll give you a heads up as soon as I have the info.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Location.watchPositionAsync not setting state as location
Im using expo-location to monitor my users location as it updates. The Location.watchPositionAsync(options, callback) function in particularĀ ...
Read more >
Location - Expo Documentation
Gets the current heading information from the device. To simplify, it calls watchHeadingAsync and waits for a couple of updates, and then returns...
Read more >
How to use the expo-location.watchHeadingAsync function in ...
Allows reading geolocation information from the device. Your app can poll for the current location or subscribe to location update events. GitHub. MIT....
Read more >
expo-location - npm
Location.watchHeadingAsync(callback). Suscribe to compass updates from the device. Arguments. callback (function) --. This function is called onĀ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found