R-based items are processed differently than Displayr's built-in features. If the R code is simple and straightforward enough, Displayr is able to process the code using Displayr's Native R Interpreter. More typically, R-based items (you will see an R Code area on the Data tab) are processed on a remote R server, and both the data and R code need to be sent to the R server for processing, see how our R servers work here.
For R Calculations on the page, you can review the timings of the different parts of processing (if using an R variable or R data set, you can copy R variable and R data set code into a Calculation for review). These timings can help you identify bottlenecks in the processing of the output where you may be able to make the output's processing more efficient. For instance, is your item spending more processing time sending over the data (can you reduce the size of the data needed?) or processing the code (can you write more efficient and vectorized code?).
Requirements
- An R-based output on the page. You can tell that the output is created using R code if there is a Data > Show Advanced Options > R Code or Data > R Code section in its object inspector. An output without this section is created on the back-end within the Displayr software, and the underlying code for it is not accessible.
Method
To see the timings for a Calculation:
With the Calculation selected, in the object inspector check Data > Show Advanced Options > Output > Show raw R output.
An example of the raw R output is below. This shows you essentially what you would see if running the R code in the basic R terminal, so you will see all of the R code that was run, and then at the bottom, you will see the summary of timings. To interpret the results for the example below:
- Started - the time the output started running.
- Finished - the time the output finished running.
- Total time: 1.58s - the total time it takes for the output to run (m = minutes, s=seconds).
- Time executing code: 1.24s - time it takes, out of the total time, to run all the lines of code in the output and do all of the calculations.
- Other overhead: .23s - time spent, out of the total time, setting up the remote R server to process the data and code.
- Time spent transferring data: .12s - our R servers are separate from the server running Displayr. Any data that is referenced in the code needs to be transferred along with the code to be executed on the cloud R server.
- Data sent to R server: 65.1KB - the size of the data sent and loaded into the R server. For example, if you are passing whole variables, the raw data for those may be bigger than a drag-and-drop built-in table that summarizes the data (i.e. sending a table will only pass the numbers and structure of the table and not the raw data).
- Data received from R server: 103KB - the size of the result returned from the R server and rendered in the output.
Technical details
Keep in mind, there will always be an overhead cost to processing via an R server. Overhead includes getting things loaded into the R session, connecting with the server, and other server-side things that need to be set up to run the code.
This is why using Displayr's Native R Interpreter can speed up performance. If Displayr's Native Interpreter is used to process the R code, the R item will not show timings and instead will say "This R code has been optimized for fast execution.", see the Use Displayr's Native R Interpreter for more detail about this.
If an output is taking a long time to recalculate, and you don't see any obvious bottlenecks in the raw R output, then you should look into Optimizing the Dependency Graph for bottlenecks in items the output depends on.
Next
Minimize the Size and Distance of Data Being Moved