Profile Neuron calculations
With Neuron, we can evaluate the accuracy and performance of compiled Wasm by using a Debug build.
Prepare the Excel file
With your Excel file, apply the appropriate mappings to identify inputs and outputs.
Add a new named range referenced to a cell called
xBuildParams. Set its value to'--build=Debugas shown in the screenshot.
Examine self-test results
Make sure to complete the steps in Prepare the Excel file.
Upload the service to Spark. Note that
Debugbuilds are slower to compile and execute and should only be used for debugging purposes only.Upon the completion of the upload, the compiler logs will contain detailed information about the Neuron self-test (see Neuron compiler messages). Download the log and inspect the file contents. Look for the
traceobject.Calculations are listed in the order they are performed.
ccell address.vvalue calculated by Neuron.eexpected calculation by Excel using the value saved into the file.matchindicates whether or notv=ewithin the accuracy described in the compiler message.soeandmoeare error metrics described in Self-test.
Profile the calculations
Make sure to complete the steps in Prepare the Excel file.
Navigate to the API Tester.
In the Raw view add the additional parameters to the
request_meta:"profile": trueenables the profiling actions. This records the start and end timestamp for the calculation of each cell.
Optionally in the
request_metayou can include"top_n_profile": {number>0}:This returns the calculation time for the
{number}of sheets, columns, rows, and cells each respectively.If this parameter is included, then the Perfetto visualization described below cannot be used.
Remember to separate these parameters with a comma (
,).Send the API call a few times to ensure the service is cached in the Spark environment.
The profile results will not be displayed in the API Tester as the contents may be very long and affect the user interface.
Submit an additional API call and identify the call to the
Executeendpoint. You can view the response of the API call. Note that the response should include an object fortraceEvents. The output depends on whether the optional"top_n_profile": {number}was provided."profile": true"profile": true and "top_n_profile": ntraceEventsfollow the Trace Event Format.This output cannot be used in Perfetto.
Copy the entire response into a text file and save the filename with a
.jsonfile extension.If you skipped the
"top_n_profile"parameter, then you can visualize the trace. Go to Perfetto UI. Select Open trace file and open the saved response.It will display a trace visualization of the calculation time trace for the formulas within a workbook.
The bars listed the highest denote the time it takes for formulas that are calculated last. They depend on the calculations from formulas that take place below them.
The lowest and longest item indicated in the trace usually indicates an area for improvement. The slower calculation time for these cells prevents the dependent cells above them from being calculated sooner.
Identify the longest calculation chain
Very long calculation chains can consume memory and lead to incomplete calculations. These long calculation chains can be identified using the steps below.
Make sure to complete the steps in Prepare the Excel file.
Upload the service to Spark. Note that
Debugbuilds are slower to compile and execute and should only be used for debugging purposes only.Navigate to the API Tester.
In the Raw view add the additional parameters to the
request_meta:"show_max_calc_chain": trueenables logging the longest calculation chain.
There will be 2 additional returned objects:
outputs.additional_outputs.max_calc_infonotes the longest calculation depth and the location of the cell.outputs.additional_outputs.max_calc_chainindicates the cells that are part of the calculation chain.
To resolve this issue we can use the
Xprecalcfunction that can evaluate long calculation chains in the middle breaking it into smaller chains.Identify a cell that is midway in the calculation chain.
In an empty part of the workbook create a new Named range called
Xprecalc. In this cell, create a formula that references the previously identified cell. For example if the middle of the calculation chain wasA123, then setXprecalcto=COUNT(A123).If there are still issues, identify more breakpoints for long calculation chains and add them to the
Xprecalc. For example, if we also identifyB456as good cell to split the same or another calculation chain, setXprecalcto=COUNT(A123,B456).
Last updated
