MATLAB: Is “webread” slow compared to “urlread” and other HTTP services

MATLAB

I have an application GUI where I need to quickly read from a RESTful API server. I have been using "webread" for a while and have noticed that "urlread" is 2x faster. However, "urlread" is no longer recommended.
My application just reads the JSON data — no images or files. What is causing this difference in performance?

Best Answer

The main difference between "webread" and "urlread", is that "webread" returns native MATLAB data types, while "urlread", simply returns the raw text. The overhead involved in converting the server response to MATLAB datatypes could possibly account for the performance difference between the two commands.
In case of a JSON response from the server, a JSON object is converted to a MATLAB struct. If the JSON object fields are not valid MATLAB struct fields, "webread" performs additional work to ensure that the resulting MATLAB struct has valid fields, as MATLAB expects structs to look a certain way. Again, this can contribute to the difference in performance. 
The HTTP Interface uses the same underlying implementation of "webread", however it gives the developer more control over the parameters of the request.  
For a workflow that is recommended, but does not return native MATLAB data types, "websave" can be used to write the raw JSON response from the server to a file, which can then later be manipulated by reading the contents from the file.
Additionally, using "webread" before MATLAB R2019b uses an older infrastructure, which can contribute to performance issues. In MATLAB R2019b, a new infrastructure was implemented that may improve the performance of the command.
Related Question