Is it faster to store a data array from the backend or fetch again with d3.json()/csv??


Right now I am using d3.json() and d3.csv() anytime my data changes, this is how I seen it in almost all examples however the data itself doesn’t change.
So given that my backend is on the same host (fastapi) but different port,
would it be faster to just store the fulfilled promises into an array and then somehow reuse that each time instead of d3.json(endpoint).then(stuff)?

It is not overly slow, but I feel like it could be faster and so I am considering ways to make that happen.

Many thanks in advance for any advice and tips I should consider.

Generally it is preferable to avoid repeating network requests, since they are often one of the slowest things that a notebook does (though not always!).

I’d approach this using two cells, once to download the data, and one to process it.

// cell 1
rawData = (await fetch(endpoint)).json()
// cell 2
stuff = {
  // something that uses rawData

That way the “stuff” processing can update whenever needed, but the network requests only need to be redone if the endpoint changes.

1 Like

thanks a lot, this is what I ended up doing more or less too. Much faster!