Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch response.json() seems slower than response.text() #6418

Closed
mchev2 opened this issue Mar 11, 2016 · 5 comments
Closed

Fetch response.json() seems slower than response.text() #6418

mchev2 opened this issue Mar 11, 2016 · 5 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@mchev2
Copy link

mchev2 commented Mar 11, 2016

Just wanted to document this performance issue (incase it really exists).

fetch_from_network = function() {
  fetch(url, {
      headers: {
        'Cache-Control': 'no-cache'
      }
    })
    .then(function(res){
      // If we do res.json, for unknown reason it is slowing the render of our very complex view. res.text() does not seem to have this issue
      return res.text();
    })
    .then(function(json){
      // setstate is called in this.process
      this.process( JSON.parse(json) );
    }.bind(this));
}.bind(this);
@satya164
Copy link
Contributor

@mchev2 Can you do some profiling and post the results?

@mchev2
Copy link
Author

mchev2 commented Mar 14, 2016

I did some independent tests and did not see any difference between res.text and res.json. I had to add in caching so res.text will work for my use case.

I'm not sure where the issue could be. Perhaps the json is too heavily nested and so there is a bottleneck. I will close this for now and let you know if I find anything else.

Thank you

@mchev2 mchev2 closed this as completed Mar 14, 2016
@MrMotski
Copy link

MrMotski commented Apr 8, 2016

@mchev2 just bringing this guy's issue to your attention, could be similar.

https://stackoverflow.com/questions/36499603/taking-too-much-time-to-call-promises-then-function/36501330#36501330

@rickli1989
Copy link

I have encountered the same issue, the responseText comes back straight away in milliseconds, but when it convert to json using .json(), it takes a few seconds, the interesting thing is if I click the screen during the .json() parsing period, it get the json data back straight away

@ide
Copy link
Contributor

ide commented Apr 24, 2016

Make sure you are:

  • profiling on device, not with Chrome debugger
  • profiling in production
  • measuring just the response.json() time and not anything else like setState.

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

6 participants