In Project “File Reader” to present a file manager-like react based web page, we are facing a problem, as we required for all the files from server, the json file for 37000 files tooks server almost 6s to respond and then the web page, depend on the cpu speed, tooks almost 9s to render, that is almost 15s to wait for user.
This is not a good result, for further investigation, we use console.log("performance fetch"+(t1-t0)/1000)
to check the performance in seconds to see each step takes how long to finish.
we can see the result
1 | performance fetch 5.283445000000938 |
that means the data preparation - re-organized data and sorting only tooks about 0.05 s
to finish , and the rendering is so much longer if we wish to finish it in initialization of the page.
But here is the fact- we don’t need to render all the sub-directories as the user don’t need to see all the files, they just want to see few of them, so we change the code like this
1 | generateMenu=(data)=>{ |
we check the isRender
state before the initialization, and if state change , that means we open a menu, then we will render the all sub-directory under that.
lets see the result:
1 | performance whole 5.466634999997041 |
now the render only took 0.13s
, that is 69 times faster than the previous result if we want to render whole 37000 files at the initialization.