Skip to content

parseAsync Blocks the main thread forever while parsing a large JSON in React native #16

@athulantonynp

Description

@athulantonynp

Describe the bug

When attempting to parse a simple JSON response using this library, I encountered performance issues. The library's parsing speed was slower compared to the native JSON.parse() method. Additionally, it caused the main thread to block indefinitely until the parsing process was completed. This experience was observed while running the code in a React Native Android application.

To Reproduce
Just create a new RN project and try to run the below code under a useEffect

export async function parseJSON() {
  try {
    for (let i = 0; i < 100; i++) {
      const response = await fetch(
        `https://microsoftedge.github.io/Demos/json-dummy-data/5MB.json`,
      );
      console.log('Got data');
      const data = await response.text();
      const parsedData = await parseAsync(data);
      console.log('Parsed data');
    }
  } catch (e) {}
}

Expected behavior
The UI shouldn't be blocked until the parsing completed and it should be same speed as the JSON.parse() (Or atleast nearest)

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

    "js-coroutines": "^2.4.36",
    "react-native": "0.74.2",

Smartphone (please complete the following information):

  • Device: Any Android phone (I have tested only on Android so far. Not sure about iOS)

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions