I use fetch in my react-native app for API calls.
This works fine in development builds, but slows down to several seconds in a release build.
The problem is not with the API; a request takes about 100~300 ms to complete (according to the ngrok inspector). This is true for both dev and release builds.
When I log the time before and after the fetch, there's a delay that I can't explain.
The simplest use case (even in a fresh [email protected] app) slows down to a crawl when I do a API call in a release build.
console.log('start request');
const response = await fetch('http://...');
console.log('request completed');
The time between these logs varies between several 100ths of ms up to 6, 7 seconds (the non-async/await approach suffers the same sluggishness).
The response is always application/json, and I unpack it using the response.json() function. But even with a response such as {"test": 123}, it's still slow.
I can imagine having done something wrong during the react-native upgrade process, but what I don't understand is why this happens even in a completely boilerplate new react-native app.
All our tests indicate that iPods (6th gen) suffer this problem, not recent iPhones. Has anyone else encountered (and hopefully been able to fix) this?
Check with
xmlhttprequestor use theaxiosinstead of fetch api. And also check the time taken for this request in curlIn the terminal:
curl -s -w 'Total: %{time_total}s\n' 'https://examplerequest.com'. So you can find what happen?